【问题标题】:$ionicSlideBoxDelegate not scrolling and not updating index$ionicSlideBoxDelegate 不滚动也不更新索引
【发布时间】:2016-10-24 06:35:31
【问题描述】:

我在模态框内有一个滑动框。

以前的滑动框在模态模板里面,相关的功能在一个控制器里面。

我意识到最好将它移动到指令中,并将所有函数移动到指令的链接函数中。

所以,这就是我所做的:

模态模板只调用指令:<my-directive></my-directive>,没有别的。

指令代码如下:

angular.module('feedback', []).directive('myDirective', [
  '$ionicSlideBoxDelegate', '$rootScope', 'Info', function($ionicSlideBoxDelegate, $rootScope, Info) {
    var linkFunction;

    linkFunction = function(scope) {

      scope.data = {
        timestamp: new Date,
        details: {
          app: Info.getAppInfo(),
          device: Info.getDeviceInfo()
        },
        user: $rootScope.currentUser,
        message: ''
      };

      scope.slideChanged = function(index) {
        scope.slideIndex = index;
      };

      scope.disableSwipe = function() {
        $ionicSlideBoxDelegate.enableSlide(true);
      };

      scope.slideTo = function(index) {
        console.log("Got here...");
        console.log("Index is: ", index);
        $ionicSlideBoxDelegate.slide(index);
      };

    };
    return {
      restrict: 'E',
      replace: false,
      templateUrl: './directives/feedback/feedback.tpl.html',
      link: linkFunction
    };
  }
]);

模板如下:

<div>
    <ion-slide-box ng-init="disableSwipe()" on-slide-changed="slideChanged(index)" class="feedback-slider" show-pager="false">

        <ion-slide>
            <ion-item class="item-icon item-icon-right" ng-click="slideTo(1)">
        </ion-slide>

        <ion-slide>
        <button class="button button-positive button-clear no-animation"
                ng-click="slideTo(0)">Back</button>
        </ion-slide>

    </ion-slide-box>
</div>

这是模板的一个旅行版本,但它应该足以解释它正在发生的事情。

基本上,没有调用任何函数。我的意思是,在打印控制台并显示预期值时调用它们,但看起来与 $ionicSlideBoxDelegate 相关的所有内容都没有被触发,我真的不明白为什么。

有什么帮助吗?

谢谢

【问题讨论】:

    标签: angularjs ionic-framework angular-directive


    【解决方案1】:

    所以,

    经过大量研究并尝试调试 ionic 功能,我设法使用以下链接的 ionic 论坛解决了这个问题:

    https://github.com/driftyco/ionic/issues/1865

    类似问题的接缝是当您的应用程序上有多个滑块时,这是 ionic 库中的一个已知问题。

    我像这样更改我的代码:

    $ionicSlideBoxDelegate.$getByHandle('feedbackDirective')._instances[0].enableSlide(false);
    

    并在 html 模板中添加了一个处理程序:

       <ion-slide-box ng-init="disableSwipe()"
                           on-slide-changed="slideChanged(index)"
                           class="hg-feedback-slider"
                           show-pager="false"
                           delegate-handle="feedbackDirective">
    
                          ...
    

    现在它又可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 2019-09-20
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多