检查数组值存在或角JS不使用手表功能数组、手表、存在、功能

由网友(〃坚强的背后是多么寒酸.)分享简介:当我键入文本区域的一些价值观,我可以通过触发cotroller功能when i typing some values in text area i can trigger a function in...
<textarea ng-model="statement" name="statement"></textarea>

当我键入文本区域的一些价值观,我可以通过触发cotroller功能

when i typing some values in text area i can trigger a function in cotroller by using

var autosave = function(newVal, oldVa){
    console.log('inside the function');
}
$scope.$watch('statement', autosave);

在这里,我要检查值数组包含一定的价值,如果存在价值,我想触发控制器中的一些功能。

here i want to check the value array contain some value, if the values exist i want to trigger some function in controller

$scope.testAry =[];

我要去推一些值

$scope.testAry.push({username: jenson});

这时候数组包含的值,所以我需要触发功能

This time the array contain the values so i need to trigger a function

   $scope.$watch('testAry', autosave); // not working 

谁能帮助我来触发自动保存功能,如果数组至少包含一个值

can anyone help me to trigger the autosave function if the array contain at least one value

推荐答案

传递第三个参数真看数组值:

Pass third parameter true to watch array values:

$scope.$watch('testAry', autosave, true);

或者你可以使用$ watchCollection。

Or you may use $watchCollection.

阅读全文

相关推荐

最新文章