$ionicSlideBoxDelegate 不滚动也不更新索引
$ionicSlideBoxDelegate not scrolling and not updating index
我在模态框内有一个滑动框。
滑动框以前在模态模板中,相关功能在控制器中。
我意识到最好将它移动到指令中,并将所有函数移动到指令的 link 函数中。
所以,这就是我所做的:
模态模板仅调用指令:<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>
这是模板的简化版,但足以解释其内容。
基本上,none 个函数被调用。我的意思是,它们在打印控制台并显示预期值时被调用,但似乎与 $ionicSlideBoxDelegate
相关的所有内容都没有被触发,我真的不明白为什么。
有什么帮助吗?
谢谢
所以,
经过大量研究并尝试调试 ionic 函数,我设法使用 ionic 论坛解决了这个 link:
https://github.com/driftyco/ionic/issues/1865
问题是当你的应用程序上有多个滑块时,这是离子库中的一个已知问题。
我这样修改我的代码:
$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">
...
现在它又能正常工作了。
我在模态框内有一个滑动框。
滑动框以前在模态模板中,相关功能在控制器中。
我意识到最好将它移动到指令中,并将所有函数移动到指令的 link 函数中。
所以,这就是我所做的:
模态模板仅调用指令:<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>
这是模板的简化版,但足以解释其内容。
基本上,none 个函数被调用。我的意思是,它们在打印控制台并显示预期值时被调用,但似乎与 $ionicSlideBoxDelegate
相关的所有内容都没有被触发,我真的不明白为什么。
有什么帮助吗?
谢谢
所以,
经过大量研究并尝试调试 ionic 函数,我设法使用 ionic 论坛解决了这个 link:
https://github.com/driftyco/ionic/issues/1865
问题是当你的应用程序上有多个滑块时,这是离子库中的一个已知问题。
我这样修改我的代码:
$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">
...
现在它又能正常工作了。