[英]I am using $scope.$apply to update an array of objects after an http call. Can anyone tell me the correct way of doing it?
$http({
method: 'post',
url : appContext('ViewAllNotifications.json'),
data : {"categoryGroupType":"ROLB","isArchived":"N","channelTypeCode":"101","limit":"20","page":$scope.allPageNumber.toString()}
}).success(function(data){
$scope.$apply(function () {
angular.forEach(data.notification,function(){
$scope.notifications.push($(this));
});
});
}).error(function(a,b,c){
console.log(a,b,c);
});
我不確定forEach是否是這樣做的正確方法。 但基本上,我正在進行無限滾動,並且每次滾動條到達底部時,我都會加載更多通知,並將其添加到$ scope.notifications數組中。
誰能告訴我這樣做的最佳方法是什么?
嘗試這個,
$http({
method: 'post',
url : appContext('ViewAllNotifications.json'),
data : {"categoryGroupType":"ROLB","isArchived":"N","channelTypeCode":"101","limit":"20","page":$scope.allPageNumber.toString()}
}).success(function(data){
angular.forEach(data.notification,function(notification){
$scope.notifications.push(notification);
});
$scope.$apply();
}).error(function(a,b,c){
console.log(a,b,c);
});
您實際上並不需要真正使用Apply,但是請嘗試一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.