$scope.loadNotification = function(page) {
showLoader(true);
NotificationService.getNotification(page).then(function(response) {
showLoader(false);
var data = response.data, notifications = data.notifications, nextPage = data.nextPage;
renderNotification(notifications, nextPage);
}, function(error) {
showLoader(false);
$scope.pageMesssag = error;
$scope.reloadNotificationBtn=true;
});
}
$scope.loadNextPage = function() {
$scope.loadNotification($scope.nextPage);
}
function renderNotification(notifications, nextPage) {
$scope.nextPage = nextPage;
if(nextPage === 0 && notifications.length === 0) {
$scope.pageMesssag = Utils.prepareErrorMessage('', "No notifications so far.");
} else if(nextPage !== 0 && nextPage === undefined){
$scope.pageMesssag = Utils.prepareErrorMessage('', "No more notifications available.");
}
$scope.notifications.push.apply($scope.notifications, notifications);
var slicedNotidications = $scope.notifications;
if(slicedNotidications.length > PAGINATION_SIZE) {
slicedNotidications = slicedNotidications.slice(0, PAGINATION_SIZE);
}
angular.forEach(notifications, function(value, key) {
if(!value.read) {
readNotifications.push(value.id);
}
});
NotificationService.storeLatestNotificcations(slicedNotidications, nextPage);
if(readNotifications.length > 0){
markNotification(readNotifications);
}
console.log("---"+$scope.nextPage);
}
这是我的HTML代码:
<ion-infinite-scroll ng-if='nextPage !== undefined' on-infinite="loadNextPage()" distance="10%"></ion-infinite-scroll>
即使loadNextPage
有某些价值, nextPage
也不会被调用
答案 0 :(得分:0)
似乎nextPage在开头是未定义的,这就是为什么没有调用loadNextPage。你需要将$ scope.nextPage设置为RenderNotification函数之外的某个值。