javascript - ngChange for multiple ngModels -


is there way call function if 1 of multiple ngmodel values change, without adding $scope.$watch?

change this:

<div>     <input ng-model="value1" ng-change="update()">     <input ng-model="value2" ng-change="update()"> </div> 

to this:

<div ng-changes="update()">     <input ng-model="value1" >     <input ng-model="value2"> </div> 

inspired simple implementation of ngchange, can traverse child tree, collect ngmodelcontrollers , register callback in $viewchangelisteners.

function ngchanges() {   return {     restrict: 'a',     link: function(scope, element, attr) {         array.prototype.foreach.call(element[0].queryselectorall("*"), function(e) {             var ngmodel = angular.element(e).controller('ngmodel');             if (ngmodel) {                               ngmodel.$viewchangelisteners.push(function() {                 scope.$eval(attr.onchanges);               })             }       })     }   } }; 

fiddle


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -