javascript - Select custom directive and ng-change -


using <select> custom directive, want run function when value changed.

html

<select name="user_type" ng-model="user_type" user-type ng-change="check_type()"> 

directive

gb_dash.directive('usertype', function(){     return{         restrict: 'a',         require: '^ngmodel',         scope:{             check_type: '&'         },         link: function(scope, elem, attrs){             scope.check_type = function(){                 console.log('changed');             }         }     } }); 

since have isolate scope, check_type not in same scope ng-change expression. , wouldn't want so.

instead, ng-model provides way register listener ngmodel.$viewchangelisteners - ngchange directive uses - hook view model change events.

require: "ngmodel", scope: { }, // mimic directive - doesn't have isolate scope link: function(scope, element, attrs, ngmodel){    ngmodel.$viewchangelisteners.push(function(){      console.log('changed');    } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -