Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法访问角度 $watch 迭代器?
我想通过这样的 $watch 捕获第一次迭代:
scope.$watch("var", myFunc); myFunc() { if (iterator === 1) ... }
您的 watch 函数将获得两个参数,“var”的当前值和前一个值。当您的手表第一次触发时,两者都是相同的,因此您可以检查它是否是第一次被调用。像这样:
var myFunc = function(value, oldValue) { if (value === oldValue) { // First run } }