AngularJS : Ng-model Binding Not Updating When Changed With JQuery


Answer :

Angular doesn't know about that change. For this you should call $scope.$digest() or make the change inside of $scope.$apply():

$scope.$apply(function() {     // every changes goes here    $('#selectedDueDate').val(dateText);  }); 

See this to better understand dirty-checking

UPDATE: Here is an example


Just use;

$('#selectedDueDate').val(dateText).trigger('input'); 

I have found that if you don't put the variable directly against the scope it updates more reliably.

Try using some "dateObj.selectedDate" and in the controller add the selectedDate to a dateObj object as so:

$scope.dateObj = {selectedDate: new Date()} 

This worked for me.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?