我通過更新超時代碼來修復您的plunkr,以便調用$scope.$apply
。您應該使用$scope.$apply
確保角度JS組件都被告知,當你使用非角AJAX調用(如jQuery)角JS模型已被更改或核心JS回調(如jQuery):http://plnkr.co/edit/iI7zpSjmB2db4ryHuzp7?p=preview
// use $timeout service so that we can automatically invoke
// the appropriate apply
$timeout(function() {
$scope.rowCollection.push({firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: '[email protected]'});
// do I need this?
$scope.displayedCollection = [].concat($scope.rowCollection);
console.log("executed");
}, 2000, true);
你也可以這樣做,如下所示:
setTimeout(function() {
$scope.$apply(function() {
$scope.rowCollection.push({firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: '[email protected]'});
// do I need this?
$scope.displayedCollection = [].concat($scope.rowCollection);
});
console.log("executed");
}, 2000);
來源
2016-11-23 22:06:39
2ps
請添加一些你的代碼,並使一個plunker。這種方式更多的偷窺傾向於幫助。 – alphapilgrim