如何使用$scope.$watch和ng-repeat
How to use $scope.$watch and ng-repeat?
我有工作代码:
$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"/>
但是我需要使用 $watch
来ng-repeat
这样的事情:
<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>
ng-更改为ng-repeat中ng模型的$watch
您可以检测输入值是否有变化
$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>
对于您的具体情况,我建议查看ngModelController $parsers并$formatters。
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController
https://stackoverflow.com/a/22843592/274500
相关文章:
- ng init中的表达式无法使用ng repeat
- Angular ng repeat order将多个字段作为一个字段
- 访问ng repeat中的第一个项目
- Angular js+ng repeat+字母数字索引不起作用
- 如何正确应用Angularjs ng repeat
- AngularJS Navigation (li ng-repeat, create header li), DOM
- 如何使用ng repeat中的选定输入更新我的对象
- 无法使用ng repeat检索动态创建的JSON对象的属性
- 使用 ng-repeat访问 ng 表单元素/值
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 如何在ng repeat angular js中使用$index
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- ng repeat在ng repeat-过滤器不工作
- 在ng repeat中使用带有orderBy的方法
- Angular JS ng-repeat
- 在ng repeat中使ng disabled为true
- AngularJS:如何在ng repeat中使用$index
- 复选框无法正常使用ng repeat,AngularJs
- 如何使用$scope.$watch和ng-repeat
- AngularJS:从ng-repeat中删除$watch