【发布时间】:2017-06-09 07:12:23
【问题描述】:
我从 API 获取对象数组,每 2 秒更新一次。我有 $watch 正在寻找此数组中的任何更改。我需要知道什么是元素或元素已更改及其索引,以便为这些已更改的元素设置背景颜色。 提前致谢。
$scope.$watch('recentUpdates', function(newValue, oldValue) {
if(oldValue != newValue && newValue != null){
$scope.recentUpdates= newValue;
console.log(newValue)
setColor(newValue) ;
}else{
console.log('hey, value is not changed!');
}
});
SetColor 函数需要获取元素的对象和索引才能更新其颜色。
【问题讨论】:
标签: javascript arrays angular angularjs-directive watch