2014-10-31 30 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