Does $watch work continuously or only ones? I have the directive that adds a prefix to names in inputs. It does the job. But it does nothing after editing those names. I expected the directive would add the prefix after editing names too every change of input value. How to improve script to get it?
Thank you Plunker: http://plnkr.co/edit/9niAm6bpro69HOx0JK2O?p=preview <!DOCTYPE html> <html> <head> <script data-require="angular.js@*" data-semver="1.4.0-beta.4" src="https://code.angularjs.org/1.4.0-beta.4/angular.js"></script> <script> console.clear(); angular.module("myApp", []) .controller("myCtrl", function($scope) { $scope.data = [ {name:"Adam"}, {name:"Michal"}, {name:"Kate"} ]; }) .directive('input', function() { return { restrict: 'E', link: function(scope, element, attrs) { scope.$watch(element, function() { if (element.text().indexOf('✔ ') > -1) return; element.val('✔' + ' ' + element.val()); }); } }; }) ; </script> </head> <body ng-app = "myApp" ng-controller = "myCtrl"> <div ng-repeat = "person in data" style="margin: 0 0 10px"> <input ng-model = "person.name"> </div> </body> </html> -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
