一个手表功能内有两个型号

时间:2014-10-31 05:48:56

标签: javascript angularjs angularjs-scope watch

假设我有一个监视这样的模型的监视功能..

 $scope.$watch('number', function () {
   $scope.number = $scope.number.replace(/\D/, '');
   $scope.number = $scope.number.replace(/\s+/g, '');
   $scope.number =  $scope.number .replace(/[\W]/g, '');
   });

此功能限制用户在输入文本框中输入特殊字符和字母。

我还有另一个文本框,它使用另一个模型ng-model="faxNumber"

我可以在我的手表功能中添加此型号名称,还是应该使用不同的手表功能?

由于

1 个答案:

答案 0 :(得分:1)

对元素数组使用$ watchCollection:

$scope.sortableItems = [
    {order: 1, text: 'foo'},
    {order: 2, text: 'bar'},

];

$scope.$watchCollection('sortableItems', function(newCol, oldCol, scope) {
    for (var index in newCol) {
        //apply operation
    }
});