ionic提供的下拉加载,是要滑动去下拉加载,没有提供api自动触发下拉加载,比如刚进页面,或者切换tab时想触发一次下拉加载。
添加如下service:
angular.module('YourApp').service('utilities', function() { this.triggerScrollViewPullToRefresh = function (scrollView) {
scrollView.__publish(
scrollView.__scrollLeft, -scrollView.__refreshHeight,
scrollView.__zoomLevel, true); var d = new Date(); scrollView.refreshStartTime = d.getTime(); scrollView.__refreshActive = true;
scrollView.__refreshHidden = false;
if (scrollView.__refreshShow) {
scrollView.__refreshShow();
}
if (scrollView.__refreshActivate) {
scrollView.__refreshActivate();
}
if (scrollView.__refreshStart) {
scrollView.__refreshStart();
}
}
});
然后在你的controller里添加方法:
angular.module('YourApp').controller('YourController',
function($scope, $ionicScrollDelegate, utilities) {
$scope.someFunc = function() {
// scrollerHandle should be the delegate-handle set on the scrollview
$scope.scrollDelegate = $ionicScrollDelegate.$getByHandle('scrollerHandle');
utilities.triggerScrollViewPullToRefresh($scope.scrollDelegate.getScrollView());
};
});
只要在你想触发的地方调用$scope.someFunc 就可以触发下拉刷新