【发布时间】:2016-05-15 04:40:19
【问题描述】:
我有工作代码:
$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>
【问题讨论】:
-
什么不起作用..请详细解释一下。
-
为什么要使用 replace(/\D+/, '');, 进行替换?
-
你不需要 $watch,使用 ng-change,这个属性就像你输入的 $watch 一样工作
-
@AmitRamoliya,我需要分别检查每个输入。问题是 ng-repeat 中的一个模型 fi.reg,因为我无法单独检查每个输入
标签: javascript angularjs