离子新手,并试图找出为什么我无法让ionicScrollDelegate正常工作。我有以下标记:
<content has-header="true" on-refresh="refreshFriends()" padded="true">
<ion-scroll delegate-handle="myScroll">
<refresher></refresher>
....
</ion-scroll>
然后在控制器中:
angular.module('starter.controllers', [])
.controller('MenuCtrl', function($scope, $ionicScrollDelegate, $http, $location, APIService) {
var delegate = $ionicScrollDelegate.$getByHandle('myScroll');
delegate.rememberScrollPosition('my-scroll-id');
delegate.scrollToRememberedPosition();
.....
}); 但是,在加载时 - 我在控制台中收到此错误:
Error: [$injector:unpr] Unknown provider: $ionicScrollDelegateProvider <- $ionicScrollDelegate
这里有什么建议吗?我在ng-view中加载内容,如下所示:
APIService.async().then(function(d) {
if (d.meta.code == 200) {
$scope.checkins = d.response.checkins.items;
}
});
所以我不确定这里是否有时间问题,但我在$ async函数中放置了$ ionicScrollDelegate的声明并没有运气。
我相信我正确地遵循了指示。谢谢!
更新 这是app.js代码:
angular.module('starter', ['ionic', 'ngRoute', 'ngAnimate', 'starter.services', 'starter.controllers'])
.config(function ($compileProvider){
// Needed for routing to work
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
})
.config(function($routeProvider, $locationProvider) {
...
});
document.addEventListener("deviceready", function(e) {
ionic.Platform.detect();
}, false);
答案 0 :(得分:5)
您是否尝试将调用包装起来以获取此类句柄?
setTimeout(function() {
var delegate = $ionicScrollDelegate.$getByHandle('myScroll');
// rest of related code included here...
},10);
这是论坛中提供的解决方案,请参阅下面的链接
http://forum.ionicframework.com/t/ionicscrolldelegate-on-view-load-event/2661
答案 1 :(得分:2)
您可以使用离子生命周期:
$scope.$on('$ionicView.loaded', function(){
console.log('$ionicView.loaded');
$ionicScrollDelegate.scrollTo(0,$rootScope.top,false);
});