javascript - AngularJS ngModel Directive with select field and ngOptions -


i'm trying have code run during link callback of ngmodel directive using angularjs on select field uses ngoptions.

module.directive("ngmodel",function(){     console.log('ng-model called');     return {       restrict: 'a',       priority: -1, // give lower priority built-in ng-model       link: function(scope, element, attr) {          console.log('watching');          scope.$watch(attr.ngmodel,function(value){                             if (value){                 console.log("changing");             }          });        }      } }); 

see fiddle demonstrates problem: http://jsfiddle.net/d3r3zwlj/3/

the first select field populated using ng-options, while second has options explicitly written out in html. if open console, can see see "changing" message when change second select field. changing first nothing.

you'll notice see 'ng-model called' , 'watching' once, though there 2 fields ng-model on them.

i'd expect ngmodel directive work on both select fields. ng-options doing preventing ngmodel working?

thanks!

looking @ doc ng-options: https://docs.angularjs.org/api/ng/directive/ngoptions

"directive info directive executes @ priority level 0."

if change priority of directive 0, runs successfully. i'm not sure implications there, that's why happening.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -