ionic的新手,并试图弄清楚为什么我无法使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;
}
});
因此,我不确定这里是否存在计时问题,但是我将$ 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);
最佳答案
您是否尝试将调用包装起来以得到这样的句柄?
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
关于javascript - ionic的ionicScrollDelegate(AngularJS),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23496534/