Skip to content

Commit 7fe987c

Browse files
committed
Fix dynamic slides
1 parent 5d68ba6 commit 7fe987c

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

Diff for: js/angular/directive/slides.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function($animate, $timeout) {
5454
this.update = function() {
5555
$timeout(function() {
5656
_this.__slider.update();
57+
_this.__slider.createLoop();
5758

5859
// Don't allow pager to show with > 10 slides
5960
if (_this.__slider.slides.length > 10) {
@@ -62,6 +63,14 @@ function($animate, $timeout) {
6263
});
6364
};
6465

66+
this.rapidUpdate = ionic.debounce(function() {
67+
_this.update();
68+
}, 50);
69+
70+
this.getSlider = function() {
71+
return _this.__slider;
72+
};
73+
6574
var options = $scope.options || {};
6675

6776
var newOptions = angular.extend({
@@ -97,6 +106,9 @@ function($animate, $timeout) {
97106
require: '?^ionSlides',
98107
transclude: true,
99108
replace: true,
100-
template: '<div class="swiper-slide" ng-transclude></div>'
109+
template: '<div class="swiper-slide" ng-transclude></div>',
110+
link: function($scope, $element, $attr, ionSlidesCtrl) {
111+
ionSlidesCtrl.rapidUpdate();
112+
}
101113
};
102114
}]);

Diff for: test/html/slides.html

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
<ion-title>Hello</ion-title>
1717
</ion-header-bar>
1818
<ion-content class="padding">
19-
<!--
20-
<ks-swiper-container override-parameters="{'loop':true}">
21-
<ks-swiper-slide class="swiper-slide" ng-repeat="s in [1,2,3,4]">
22-
<img ng-src="http://api.randomuser.me/portraits/thumb/men/{{s}}.jpg">
23-
</ks-swiper-slide>
24-
</ks-swiper-container>
25-
-->
2619
<ion-slides options="options">
2720
<ion-slide-page>
2821
<h2>Journey to HD 219134 b</h2>
@@ -105,10 +98,22 @@ <h2>Life on HD 219134 b</h2>
10598
</ion-pane>
10699
<script>
107100
angular.module('slidesTest', ['ionic'])
108-
.controller('MyCtrl', ['$scope', function($scope) {
101+
.controller('MyCtrl', ['$scope', '$interval', function($scope, $interval) {
109102
$scope.options = {
110103
loop: true
111104
}
105+
/*
106+
$scope.extraSlides = [];
107+
var i = 0;
108+
var c = $interval(function() {
109+
$scope.extraSlides.push({
110+
id: ++i
111+
})
112+
if(i > 2) {
113+
$interval.cancel(c);
114+
}
115+
}, 2000)
116+
*/
112117
}]);
113118
</script>
114119
</body>

0 commit comments

Comments
 (0)