3

在我的 Ionic 1.3.1 应用程序中,我使用该ion-slides组件来显示问卷的各个部分:

<ion-slides options="vm.options" slider="data.slider">
        <ion-slide-page ng-repeat="s in ::vm.sections">
            <div class="bar bar-header bar-positive">
                <button class="button button-small button-icon icon ion-chevron-left"
                        ng-click="vm.previous()"
                        ng-show="::$index !== 0"></button>
                <h1 class="title">{{::s.text}}</h1>
                <button class="button button-small button-icon icon ion-chevron-right"
                        ng-click="vm.next()"
                        ng-show="::($index + 1) < vm.sections.length"></button>
            </div>
            <ion-content class="has-header">
               <div ng-if="s.include" ng-show="s.show">
                  <!--My content-->
               </div>
            </ion-content>
        </ion-slide-page>
    </ion-slides>

在我的控制器中,我监听 slideChangeStart:

    $scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
        alert('slideChangeStart');
        vm.activeIndex = slider.activeIndex;
        vm.propertySurvey.CurrentSectionIndex = vm.activeIndex;

        //include is used on an ng-if so elements are removed from the dom
        //and the number of watchers is reduced
        //also, the slider displays the contents of the 
        //previous slide unless they are explicitly hidden
        vm.sections[slider.previousIndex].include = false;
        vm.sections[slider.previousIndex].show = false;

        initialiseQuestions(vm.activeIndex);
    });

当我单击调用slider.slidePrev()或的上一个和下一个按钮时,slider.slideNext()slideChangeStart事件会触发 - 我会看到警报。但是,如果我使用手势滑动页面 - 标题会按预期更改,但事件不会触发。我试过在我的选项中关闭滑动但没有成功(反正不是我的首选解决方案):

vm.options = {
   noSwiping: true,
   effect: 'fade'
}

更新 我尝试使用slideChangeEnd,但该事件也没有触发。因此,我将所有代码移到了我从,和方法gotoSlide(index)调用的单个方法中- 这样我就不会依赖 ion-slides 事件。我在我的 ion-slide-page 组件中添加了 Ionic on-swipe 指令,看看它们是否可以工作:nextpreviouspagerClick

<ion-slide-page ng-repeat="s in ::vm.sections" 
                on-swipe-left="vm.next()" 
                on-swipe-right="vm.previous()">

这使得在 Ripple 模拟器中滑动工作(以前根本不工作),但它仍然不能在我的任何 android 设备上工作。同样,滑动事件似乎没有触发。

我正在使用人行横道插件

4

2 回答 2

0

如果我删除该effect选项,问题就会消失。所以这有效:

vm.options = {
   noSwiping: false,
   speed: 300
}

而且,由于无论如何这些都是默认值,我最终完全删除了选项对象。

NB 用 'slide' 替换 'fade' 不起作用

参考:http: //ionicframework.com/docs/api/directive/ionSlides/

于 2016-09-21T08:13:24.973 回答
0

我有一个类似的问题,上面的答案对我不起作用,所以我想我会分享一下做了什么:根据Swiper API(它是 ion-slides 的基础),您可以将基于事件的回调直接添加到小部件。

以下对我有用(假设 scope.slider 对象......)

//the 'slideChangeStart' event has a slider argument in its callback
scope.slider.on('slideChangeStart', function(slider) {
  //do stuff - maybe you want to store the activeIndex
  scope.indexIReallyCareAbout = slider.activeIndex;
});

Swiper API 给出了一个事件列表,这些事件可以在标题Callbacks下的“on”回调函数中命名

于 2017-01-13T23:57:56.163 回答