2014-10-31 56 views
0

假设,如果我有一个手表功能手表这样的模型..两款车型一个表内的功能

$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"

我可以在我的手表功能添加此型号名称以及或者我应该使用不同的手表功能的其他文本框?

感谢

+0

我想一个更好的办法将是设置类型为'number',然后使用验证器来验证不是更新的价值vlaue – 2014-10-31 05:52:44

+0

谢谢@Arun P Johny – forgottofly 2014-10-31 06:36:46

回答

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 
    } 
}); 
+0

谢谢@Mukund Kumar,但是如果我有另外一组元素,我可以在这个手表函数中添加元素名称吗? – forgottofly 2014-10-31 06:38:45

+0

没有。 $ watchCollection只能使用一组元素,我们必须为其他元素编写其他$ watchCollection。 – 2014-10-31 06:43:49

+0

好的,谢谢@Mukund – forgottofly 2014-10-31 07:24:23