在我的 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()
or slider.slideNext()
, the slideChangeStart
事件触发 - 我看到了警报。但是,如果我使用手势滑动页面 - 标题会按我的预期发生变化,但事件不会触发。我尝试在选项中关闭滑动,但没有成功(无论如何都不是我的首选解决方案):
vm.options = {
noSwiping: true,
effect: 'fade'
}
UPDATE我尝试使用slideChangeEnd
但该事件也没有触发。
所以我将所有代码移到一个单一的gotoSlide(index)
我从我的调用的方法next
, previous
and pagerClick
方法 - 这样我就不再依赖离子滑动事件。
我将 Ionic on-swipe 指令添加到我的 ion-slide-page 组件中,看看它们是否有效:
<ion-slide-page ng-repeat="s in ::vm.sections"
on-swipe-left="vm.next()"
on-swipe-right="vm.previous()">
这使得滑动在 Ripple 模拟器中工作(之前根本无法工作),但它仍然无法在我的任何 Android 设备上工作。同样,滑动事件似乎没有触发。
我正在使用 Crosswalk 插件