【发布时间】:2015-03-12 08:57:10
【问题描述】:
我正在使用 ionic 框架来创建一个基本的 Feed 应用程序。我开始复习了,但我的 ion-infinite-scroll 遇到了问题。
Feed.html
<ion-content ng-controller="FeedController" >
<ion-refresher pulling-text="Pull to refresh.." on-refresh="get_feeds()" refreshing-text="Fetching ..." refreshing-icon="ion-loading-b">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="question in questions">
<div class="item item-divider">
{{question.question}}
</div>
<div class="item" ng-bind-html="question.answer | trustHtml">
</div>
</ion-item>
</ion-list>
<ion-infinite-scroll
on-infinite="get_more()"
distance="1%">
</ion-infinite-scroll>
</ion-content>
Feed.js
(function(){
"use strict";
angular.module( 'app.controllers' ).controller( 'FeedController',
[ 'eTobb', 'Users', '$scope', '$timeout', function( eTobb, Users, $scope, $timeout) {
var pageIndex = 1;
$scope.questions = [];
$scope.get_feeds = function(pageIndex){
eTobb.get($scope.apiCall, { user_id: Users.id, page: 0 }, function(response) {
if ( response ){
$scope.questions = $scope.questions.concat(response);
console.log($scope.questions);
}
})
.finally(function(){
$scope.$broadcast('scroll.refreshComplete');
$scope.$broadcast('scroll.infiniteScrollComplete');
});
};
$scope.get_more = function(){
$scope.get_feeds(pageIndex);
pageIndex = pageIndex + 1;
console.log('why the hell am i being called?');
};
}
]);
})();
问题
on-infinite 属性上定义的方法在页面加载时调用两次,然后在每次到达页面底部时正常调用(一次)。 有谁知道为什么会这样?
【问题讨论】:
-
"console.log('为什么我会被叫到?');"我想知道同样的 Jajajajajaja
标签: angularjs scroll ionic-framework infinite ionic