javascript ionicScrollDelegate 与 ionic (AngularJS)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23496534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:59:48  来源:igfitidea点击:

ionicScrollDelegate with ionic (AngularJS)

javascriptangularjsionic-framework

提问by gregavola

New to ionic, and trying to figure out why I can't get ionicScrollDelegate to work correctly. I have this following markup:

离子的新手,并试图弄清楚为什么我无法让 ionicScrollDelegate 正常工作。我有以下标记:

 <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:

这里有什么建议吗?我在 ng-view 中加载内容,如下所示:

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.

所以我不确定这里是否有计时问题,但我将 $ionicScrollDelegate 的声明放在这个异步函数中,但没有运气。

I believe I am following the directions correctly. Thanks!

我相信我正确地遵循了指示。谢谢!

UPDATEHere is the app.js code:

更新这是 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);

回答by Aaron Saunders

did 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.com/t/ionicscrolldelegate-on-view-load-event/2661

http://forum.ionicframework.com/t/ionicscrolldelegate-on-view-load-event/2661

回答by Yernar Amergaliyev

You can use ionic life cycle:

您可以使用离子生命周期:

$scope.$on('$ionicView.loaded', function(){

        console.log('$ionicView.loaded');

        $ionicScrollDelegate.scrollTo(0,$rootScope.top,false);
    });