15
15
*
16
16
* @usage
17
17
* ```html
18
- * <ion-slides options="options" slider="data.slider">
19
- * <ion-slide-page>
20
- * <div class="box blue"><h1>BLUE</h1></div>
21
- * </ion-slide-page>
22
- * <ion-slide-page>
23
- * <div class="box yellow"><h1>YELLOW</h1></div>
24
- * </ion-slide-page>
25
- * <ion-slide-page>
26
- * <div class="box pink"><h1>PINK</h1></div>
27
- * </ion-slide-page>
28
- * </ion-slides>
18
+ * <ion-content scroll="false">
19
+ * <ion-slides options="options" slider="data.slider">
20
+ * <ion-slide-page>
21
+ * <div class="box blue"><h1>BLUE</h1></div>
22
+ * </ion-slide-page>
23
+ * <ion-slide-page>
24
+ * <div class="box yellow"><h1>YELLOW</h1></div>
25
+ * </ion-slide-page>
26
+ * <ion-slide-page>
27
+ * <div class="box pink"><h1>PINK</h1></div>
28
+ * </ion-slide-page>
29
+ * </ion-slides>
30
+ * </ion-content>
29
31
* ```
30
32
*
31
33
* ```js
32
34
* $scope.options = {
33
35
* loop: false,
34
- * effect: fade,
36
+ * effect: ' fade' ,
35
37
* speed: 500,
36
38
* }
37
- * $scope.data = {};
38
- * $scope.$watch('data.slider', function(nv, ov) {
39
- * $scope.slider = $scope.data.slider;
40
- * })
39
+ *
40
+ * $scope.$on("$ionicSlides.sliderInitialized", function(event, data){
41
+ * // data.slider is the instance of Swiper
42
+ * $scope.slider = data.slider;
43
+ * });
44
+ *
45
+ * $scope.$on("$ionicSlides.slideChangeStart", function(event, data){
46
+ * console.log('Slide change is beginning');
47
+ * });
48
+ *
49
+ * $scope.$on("$ionicSlides.slideChangeEnd", function(event, data){
50
+ * // note: the indexes are 0-based
51
+ * $scope.activeIndex = data.activeIndex;
52
+ * $scope.previousIndex = data.previousIndex;
53
+ * });
54
+ *
55
+ * ```
56
+ *
57
+ * ## Slide Events
58
+ *
59
+ * The slides component dispatches events when the active slide changes
60
+ *
61
+ * <table class="table">
62
+ * <tr>
63
+ * <td><code>$ionicSlides.slideChangeStart</code></td>
64
+ * <td>This event is emitted when a slide change begins</td>
65
+ * </tr>
66
+ * <tr>
67
+ * <td><code>$ionicSlides.slideChangeEnd</code></td>
68
+ * <td>This event is emitted when a slide change completes</td>
69
+ * </tr>
70
+ * <tr>
71
+ * <td><code>$ionicSlides.sliderInitialized</code></td>
72
+ * <td>This event is emitted when the slider is initialized. It provides access to an instance of the slider.</td>
73
+ * </tr>
74
+ * </table>
75
+ *
76
+ *
77
+ * ## Updating Slides Dynamically
78
+ * When applying data to the slider at runtime, typically everything will work as expected.
79
+ *
80
+ * In the event that the slides are looped, use the `updateLoop` method on the slider to ensure the slides update correctly.
81
+ *
82
+ * ```
83
+ * $scope.$on("$ionicSlides.sliderInitialized", function(event, data){
84
+ * // grab an instance of the slider
85
+ * $scope.slider = data.slider;
86
+ * });
87
+ *
88
+ * function dataChangeHandler(){
89
+ * // call this function when data changes, such as an HTTP request, etc
90
+ * if ( $scope.slider ){
91
+ * $scope.slider.updateLoop();
92
+ * }
93
+ * }
41
94
* ```
42
95
*
43
96
*/
@@ -61,11 +114,6 @@ function($animate, $timeout, $compile) {
61
114
'</div>' ,
62
115
controller : [ '$scope' , '$element' , function ( $scope , $element ) {
63
116
var _this = this ;
64
- var _watchHandler = null ;
65
- var _enterHandler = null ;
66
- var _afterLeaveHandler = null ;
67
- var _modalRemovedHandler = null ;
68
- var _modalPresentedHandler = null ;
69
117
70
118
this . update = function ( ) {
71
119
$timeout ( function ( ) {
@@ -96,52 +144,6 @@ function($animate, $timeout, $compile) {
96
144
_this . update ( ) ;
97
145
} , 50 ) ;
98
146
99
- this . updateLoop = ionic . debounce ( function ( ) {
100
- if ( _this . _options . loop ) {
101
- _this . __slider . updateLoop ( ) ;
102
- }
103
- } , 50 ) ;
104
-
105
- this . watchForChanges = function ( ) {
106
- if ( ! _watchHandler ) {
107
- // if we're not already watching, start watching
108
- _watchHandler = $scope . $watch ( function ( ) {
109
- console . log ( "Watch triggered" ) ;
110
- _this . updateLoop ( ) ;
111
- } ) ;
112
- }
113
- } ;
114
-
115
- this . stopWatching = function ( ) {
116
- if ( _watchHandler ) {
117
- console . log ( "Stopping watching..." ) ;
118
- _watchHandler ( ) ;
119
- _watchHandler = null ;
120
- }
121
- } ;
122
-
123
- this . cleanUpEventHandlers = function ( ) {
124
- if ( _enterHandler ) {
125
- _enterHandler ( ) ;
126
- _enterHandler = null ;
127
- }
128
-
129
- if ( _afterLeaveHandler ) {
130
- _afterLeaveHandler ( ) ;
131
- _afterLeaveHandler = null ;
132
- }
133
-
134
- if ( _modalRemovedHandler ) {
135
- _modalRemovedHandler ( ) ;
136
- _modalRemovedHandler = null ;
137
- }
138
-
139
- if ( _modalPresentedHandler ) {
140
- _modalPresentedHandler ( ) ;
141
- _modalPresentedHandler = null ;
142
- }
143
- } ;
144
-
145
147
this . getSlider = function ( ) {
146
148
return _this . __slider ;
147
149
} ;
@@ -160,37 +162,22 @@ function($animate, $timeout, $compile) {
160
162
$timeout ( function ( ) {
161
163
var slider = new ionic . views . Swiper ( $element . children ( ) [ 0 ] , newOptions , $scope , $compile ) ;
162
164
165
+ $scope . $emit ( "$ionicSlides.sliderInitialized" , { slider : slider } ) ;
166
+
163
167
_this . __slider = slider ;
164
168
$scope . slider = _this . __slider ;
165
169
166
170
$scope . $on ( '$destroy' , function ( ) {
167
171
slider . destroy ( ) ;
168
172
_this . __slider = null ;
169
- _this . stopWatching ( ) ;
170
- _this . cleanUpEventHandlers ( ) ;
171
-
172
- } ) ;
173
-
174
- _this . watchForChanges ( ) ;
175
-
176
- _enterHandler = $scope . $on ( "$ionicView.enter" , function ( ) {
177
- _this . watchForChanges ( ) ;
178
173
} ) ;
179
-
180
- _afterLeaveHandler = $scope . $on ( "$ionicView.afterLeave" , function ( ) {
181
- _this . stopWatching ( ) ;
182
- } ) ;
183
-
184
- _modalRemovedHandler = $scope . $on ( "$ionic.modalRemoved" , function ( ) {
185
- _this . stopWatching ( ) ;
186
- } ) ;
187
-
188
- _modalPresentedHandler = $scope . $on ( "$ionic.modalPresented" , function ( ) {
189
- _this . watchForChanges ( ) ;
190
- } ) ;
191
-
192
174
} ) ;
193
175
176
+ $timeout ( function ( ) {
177
+ // if it's a loop, render the slides again just incase
178
+ _this . rapidUpdate ( ) ;
179
+ } , 200 ) ;
180
+
194
181
} ] ,
195
182
196
183
link : function ( $scope ) {
0 commit comments