1

I have working code:

$scope.$watch('vm.reg', function (newValue) {
  if (newValue !=  null) {
    vm.reg = newValue.replace(/\D+/, '');
  }
});
<input type="text" class="form-control" name="dest_regex" ng-model="vm.reg"/>

But I need to use $watch for ng-repeat something like this:

<div ng-repeat="fi in filterElments">
    <input type="text" class="form-control" name="dest_regex" ng-model="fi.reg"/>

    <!--<input type="text" class="form-control" name="dest_regex" ng-model="fi.reg"/>
    <input type="text" class="form-control" name="dest_regex" ng-model="fi.reg"/>
     .................. -->
</div>
Jeroen
  • 60,696
  • 40
  • 206
  • 339
Decastrio
  • 133
  • 2
  • 10

2 Answers2

2

ng-Change as $watch for your ng-models in ng-repeat

you can detect if input value has changes

$scope.replacing = function(item){
  //do somthing
}
<div ng-repeat="fi in filterElments">
    <input type="text" class="form-control" name="dest_regex" ng-model="fi.reg" ng-change="replacing(fi)"/>
</div>
Maher
  • 2,517
  • 1
  • 19
  • 32
0

For your specific case I would suggest to look at ngModelController $parsers and $formatters.

https://docs.angularjs.org/api/ng/type/ngModel.NgModelController

https://stackoverflow.com/a/22843592/274500

Community
  • 1
  • 1
Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176