AngularJS prevent ngModel sync -


i have simple directive called po-datepicker, displays datepicker on screen, allows user type date manually:

<input type="text" ng-model="model" po-datepicker required /> 

and directive:

myapp.directive('podatepicker', function () {     return {         require: ['?^ngmodel'],         restrict: 'a',         link: function ($scope, elem, attrs, ctrl) {             var ngmodel = ctrl[0];             var picker = elem.datepicker();              picker.on('changedate', function(e) {                 ngmodel.$setviewvalue(e.date);                 ...             });              elem.parent().find('button').on('click', function() {                 picker.datepicker('show');             });              var changefn = function(e) {                 // here have logic calls $setviewvalue();             };              picker.on('hide', changefn);             elem.on('keyup blur', changefn);         }     }; }); 

this works expected, when try type value in input, updates ngmodel, changing variable in scope, how can prevent ngmodel being changed in input?

here plunkr, try manually writing value , you'll understand i'm talking.

actually, after research, found solution problem.

what found on forums , questions needed unbind element's events, this:

elem.unbind('input').unbind('keydown').unbind('change'); 

but solution didn't work expected.

the problem i'm using angular 1.2.x, found out need set priority directive, such as:

return {     require: ['?^ngmodel'],     priority: 1,     ... } 

the priority: 1 needed in case, because of priority of internal angular.js directives.

here updated plunker right priority set up.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -