检查数组值存在或角JS不使用手表功能 [英] Check array value exist or not using watch function in angular js
本文介绍了检查数组值存在或角JS不使用手表功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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.
这篇关于检查数组值存在或角JS不使用手表功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文