Coder Social home page Coder Social logo

Comments (5)

katemihalikova avatar katemihalikova commented on July 29, 2024

You should use the same as with any other ng-model-enabled input.

<div ion-datetime-picker ng-model="datetime" ng-change="onChange()">{{datetime}}</div>
$scope.datetime = new Date(); // set start date and time
$scope.onChange = function() {}; // set callback

from ion-datetime-picker.

huangfang2015 avatar huangfang2015 commented on July 29, 2024

Thanks.

from ion-datetime-picker.

gqferreira avatar gqferreira commented on July 29, 2024

I could not make it work properly. My code:

app.js
var app = angular.module('app', ['ionic', 'ionic.service.core', 'ionic.service.analytics', 'ngMessages', 'ngCordova', 'ionic.utils', 'app.controllers', 'app.routes', 'app.services', 'app.directives', 'angular-md5', 'ion-datetime-picker']);

controllers.js

.controller('MyController', function ($scope, $ionicPopup, AuthService, $state, $ionicLoading, $interval) {
   //Initial value
    $scope.datetime = new Date();

    //Event when confirm datetime
    $scope.datetimepickerEvent = function (){
                alert($scope.datetime);
            };

    //Function called before calendar show
    $scope.updateDatetime = function () {
                alert("I am working");
                $scope.datetime = new Date();
                alert($scope.datetime); // The datetime really update.
            };

});

home.html
<div ion-datetime-picker ng-model="datetime" ng-change="datetimepickerEvent()" ng-click="updateDatetime()">{{datetime}}</div>

Problem
After confirm datetime, the $scope.datetime doesn't show the same value in home.html and controllers.js, my function updateDatetime() really update datetime but can't update the datetime used by calendar. If I press Cancel button, this does not happen. If I confirm datetime in calendar and I need reopen it, the current datetime is outdated.

Is this a bug?
Thank you for your attention.
Gustavo Ferreira.

from ion-datetime-picker.

katemihalikova avatar katemihalikova commented on July 29, 2024

This is not a bug, but a lack of knowledge about how angular and javascript work.

Please see #14 and this demo made from your code to understand why it does not work for you.

from ion-datetime-picker.

gqferreira avatar gqferreira commented on July 29, 2024

Ok, thank you.

from ion-datetime-picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.