我使用这个函数来观察一组对象的变化:
$scope.$watch('Data', function (newVal) { /*...*/ }, true);
如何获取属性已更改的对象,以便可以将其推送到数组中?例如:
var myApp = angular.module("myApp", []);
myApp.factory("Data", function(){
var Data = [{id:1, property: "Random"}, {id:2, property: "Random again"}];
return Data;
});
var myBigArray = [];
function tableCtrl($scope, Data){
$scope.TheData = Data;
$scope.$watch("TheData", function() {
//Here an object should be pushed
myBigArray.push(">>Object in which property has been changed <<<");
}, true);
}