小性能技巧如果有人有關鍵的數據存儲服務的種類 - >值對:
如果你有一個服務叫做的數據存儲,你只要您的大數據對象發生更改,就可以更新時間戳。 這種方式,而不是深入觀察整個對象,你只是看着變化的時間戳。
app.factory('dataStore', function() {
var store = { data: [], change: [] };
// when storing the data, updating the timestamp
store.setData = function(key, data){
store.data[key] = data;
store.setChange(key);
}
// get the change to watch
store.getChange = function(key){
return store.change[key];
}
// set the change
store.setChange = function(key){
store.change[key] = new Date().getTime();
}
});
而在一個指令你只能眼睜睜地看着時間戳改變
app.directive("myDir", function ($scope, dataStore) {
$scope.dataStore = dataStore;
$scope.$watch('dataStore.getChange("myKey")', function(newVal, oldVal){
if(newVal !== oldVal && newVal){
// Data changed
}
});
});
可能重複[如何深觀看angularjs數組?](http://stackoverflow.com/questions/14712089/how-to-深入觀察數組角度js) – lort