0
如果对象不存在,这个OR语法/逻辑在Angular.js中是错误的吗?我一直得到TypeError: Cannot read property 'timestamp' of undefined
。但我在chrome调试器中验证了其中至少有一个存在,如sseHandler.result.httpPortResult.timestamp
。
$scope.$watch(function(){
return sseHandler.result.cpuResult.timestamp ||
sseHandler.result.networkResult.timestamp ||
sseHandler.result.httpPortResult.timestamp;
}, function(){
if (sseHandler.result.cpuResult) {
console.log("yes");
cpuUpdate(sseHandler.result);
}
});
}]);
+1 to $ watchCollection。我希望Angular.js文档的api集合有更好的索引。 – dman