Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

Since this must have an input element as a parent, you could just use

<input type="text" ng-model="foo" ngChange="myOnChangeFunctionng-change="myOnChangeFunction()"> 

Alternatively, you could use the ngModelControllerngModelController and add a function to $formatters$formatters, which executes functions on input change. See http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController

.directive("myDirective", function() { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attr, ngModel) { ngModel.$formatters.push(function(value) { // Do stuff here, and return the formatted value. }); }; }; 

Since this must have an input element as a parent, you could just use

<input type="text" ng-model="foo" ngChange="myOnChangeFunction()"> 

Alternatively, you could use the ngModelController and add a function to $formatters, which executes functions on input change. See http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController

.directive("myDirective", function() { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attr, ngModel) { ngModel.$formatters.push(function(value) { // Do stuff here, and return the formatted value. }); }; }; 

Since this must have an input element as a parent, you could just use

<input type="text" ng-model="foo" ng-change="myOnChangeFunction()"> 

Alternatively, you could use the ngModelController and add a function to $formatters, which executes functions on input change. See http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController

.directive("myDirective", function() { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attr, ngModel) { ngModel.$formatters.push(function(value) { // Do stuff here, and return the formatted value. }); }; }; 
Source Link
Jmr
  • 12.1k
  • 4
  • 41
  • 33

Since this must have an input element as a parent, you could just use

<input type="text" ng-model="foo" ngChange="myOnChangeFunction()"> 

Alternatively, you could use the ngModelController and add a function to $formatters, which executes functions on input change. See http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController

.directive("myDirective", function() { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attr, ngModel) { ngModel.$formatters.push(function(value) { // Do stuff here, and return the formatted value. }); }; };