New to ionic, and trying to figure out why I can't get ionicScrollDelegate to work correctly. I have this following markup:
<content has-header="true" on-refresh="refreshFriends()" padded="true">
<ion-scroll delegate-handle="myScroll">
<refresher></refresher>
....
</ion-scroll>
And then in the controller:
angular.module('starter.controllers', [])
.controller('MenuCtrl', function($scope, $ionicScrollDelegate, $http, $location, APIService) {
var delegate = $ionicScrollDelegate.$getByHandle('myScroll');
delegate.rememberScrollPosition('my-scroll-id');
delegate.scrollToRememberedPosition();
.....
}); However, on load - I get this error in the console:
Error: [$injector:unpr] Unknown provider: $ionicScrollDelegateProvider <- $ionicScrollDelegate
Any advice here? I am loading content in a ng-view, like this:
APIService.async().then(function(d) {
if (d.meta.code == 200) {
$scope.checkins = d.response.checkins.items;
}
});
So I'm not sure if there a timing thing here, but I placed the declaring of the $ionicScrollDelegate, inside this async function and had no luck.
I believe I am following the directions correctly. Thanks!
UPDATE Here is the app.js code:
angular.module('starter', ['ionic', 'ngRoute', 'ngAnimate', 'starter.services', 'starter.controllers'])
.config(function ($pileProvider){
// Needed for routing to work
$pileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
})
.config(function($routeProvider, $locationProvider) {
...
});
document.addEventListener("deviceready", function(e) {
ionic.Platform.detect();
}, false);
New to ionic, and trying to figure out why I can't get ionicScrollDelegate to work correctly. I have this following markup:
<content has-header="true" on-refresh="refreshFriends()" padded="true">
<ion-scroll delegate-handle="myScroll">
<refresher></refresher>
....
</ion-scroll>
And then in the controller:
angular.module('starter.controllers', [])
.controller('MenuCtrl', function($scope, $ionicScrollDelegate, $http, $location, APIService) {
var delegate = $ionicScrollDelegate.$getByHandle('myScroll');
delegate.rememberScrollPosition('my-scroll-id');
delegate.scrollToRememberedPosition();
.....
}); However, on load - I get this error in the console:
Error: [$injector:unpr] Unknown provider: $ionicScrollDelegateProvider <- $ionicScrollDelegate
Any advice here? I am loading content in a ng-view, like this:
APIService.async().then(function(d) {
if (d.meta.code == 200) {
$scope.checkins = d.response.checkins.items;
}
});
So I'm not sure if there a timing thing here, but I placed the declaring of the $ionicScrollDelegate, inside this async function and had no luck.
I believe I am following the directions correctly. Thanks!
UPDATE Here is the app.js code:
angular.module('starter', ['ionic', 'ngRoute', 'ngAnimate', 'starter.services', 'starter.controllers'])
.config(function ($pileProvider){
// Needed for routing to work
$pileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
})
.config(function($routeProvider, $locationProvider) {
...
});
document.addEventListener("deviceready", function(e) {
ionic.Platform.detect();
}, false);
Share
Improve this question
edited May 6, 2014 at 17:11
gregavola
asked May 6, 2014 at 13:47
gregavolagregavola
2,5397 gold badges30 silver badges48 bronze badges
3
- The code you have shown worked for me. Can you show all your angular.module definitions? Sounds like a module dependency is missing somewhere in the chain. – tasseKATT Commented May 6, 2014 at 15:44
- I've added the module definitions to the post. – gregavola Commented May 6, 2014 at 17:11
- Sorry, no idea: plnkr.co/edit/DtW59yYfVPS1r1TpDOBG?p=preview – tasseKATT Commented May 6, 2014 at 19:20
2 Answers
Reset to default 5did you try wrapping the call to get the handle like this?
setTimeout(function() {
var delegate = $ionicScrollDelegate.$getByHandle('myScroll');
// rest of related code included here...
},10);
This was a solution provided here in the forums, see link below
http://forum.ionicframework./t/ionicscrolldelegate-on-view-load-event/2661
You can use ionic life cycle:
$scope.$on('$ionicView.loaded', function(){
console.log('$ionicView.loaded');
$ionicScrollDelegate.scrollTo(0,$rootScope.top,false);
});