最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Angular datepicker not firing ng-change - Stack Overflow

matteradmin6PV0评论

I am having a problem in datepicker with ng-change. The ng-change event is not firing when I change the value by "clicking the date" but working when I change the value by "typing the date".

Here's my code.

<input ng-change="date_change();" ng-model="date_to" id="recon-date" name= "date_to" type="text" class="form-control" date-time view="month" auto-close="true" min-view="month" format="MM-DD-YYYY">

I trace the problem by investigating the datepicker.js. I found out (if I'm correct) that the ngModelController.serViewValue() and $render() is not firing the ng-change.

I tried to add scope.$apply() but no luck. I am debugging this for hours and still no progress.

P.S. I don't want to use $scope.$watch() to solve this problem.

Thankss!!

I am having a problem in datepicker with ng-change. The ng-change event is not firing when I change the value by "clicking the date" but working when I change the value by "typing the date".

Here's my code.

<input ng-change="date_change();" ng-model="date_to" id="recon-date" name= "date_to" type="text" class="form-control" date-time view="month" auto-close="true" min-view="month" format="MM-DD-YYYY">

I trace the problem by investigating the datepicker.js. I found out (if I'm correct) that the ngModelController.serViewValue() and $render() is not firing the ng-change.

I tried to add scope.$apply() but no luck. I am debugging this for hours and still no progress.

P.S. I don't want to use $scope.$watch() to solve this problem.

Thankss!!

Share Improve this question asked Feb 19, 2017 at 4:21 aldesabidoaldesabido 1,2882 gold badges18 silver badges38 bronze badges 4
  • Possible duplicate of angularjs timepicker ng-change – Naghaveer R Commented Feb 19, 2017 at 5:00
  • Thanks but I dont want to use $watch event. I have so many date with ngchange and dont want to create $watch in every single one of them. – aldesabido Commented Feb 19, 2017 at 5:33
  • Try to use md-datepicker or angular-datepicker.js instead of datepicker.js – Naghaveer R Commented Feb 19, 2017 at 5:46
  • Gonna try that. Thanks. – aldesabido Commented Feb 19, 2017 at 8:36
Add a ment  | 

3 Answers 3

Reset to default 2

Without ng-change, use a watch

$scope.date_to;

$scope.$watch("date_to", function(newValue, oldValue) {
    console.log("I've changed : ", to date);
});

Use $apply, May this will help you.

var scope=angular.element($('#recon-date')).scope();    
scope.$apply(); 

Use this onchange="angular.element(this).scope().photoChange(this)" instead of this ng-change="photoChange(this)"

Post a comment

comment list (0)

  1. No comments so far