|
1 | 1 | import { Component, ViewChild } from '@angular/core';
|
2 |
| -import { AlertController, NavController, Slides, IonicPage } from 'ionic-angular'; |
| 2 | +import { NavController, Slides, IonicPage } from 'ionic-angular'; |
3 | 3 |
|
4 | 4 | @IonicPage()
|
5 | 5 | @Component({
|
6 | 6 | selector: 'page-slide-custom-pagination',
|
7 | 7 | templateUrl: 'slide-custom-pagination.html'
|
8 | 8 | })
|
9 | 9 | export class SlideCustomPaginationPage {
|
10 |
| - @ViewChild('slider') slider: Slides; |
11 |
| - |
12 |
| - options: any; |
13 |
| - showSlide = true; |
14 |
| - |
15 |
| - customPaginationNumbers = { |
16 |
| - pager: true, |
17 |
| - autoplay: 2000, |
18 |
| - paginationClickable: true, |
19 |
| - paginationBulletRender: (index, className) => { |
20 |
| - return '<span class="custom-pagination ' + className + '">' + (index + 1) + '</span>'; |
| 10 | + @ViewChild('sliderOne') sliderOne: Slides; |
| 11 | + @ViewChild('sliderTwo') sliderTwo: Slides; |
| 12 | + @ViewChild('sliderThree') sliderThree: Slides; |
| 13 | + |
| 14 | + slides = [ |
| 15 | + { |
| 16 | + title: "Dream's Adventure", |
| 17 | + imageUrl: "assets/img/lists/wishlist-1.jpg", |
| 18 | + songs: 2, |
| 19 | + private: false |
21 | 20 | },
|
22 |
| - onInit: function (swiper) { |
23 |
| - this.slider = swiper; |
24 |
| - // Now you can do whatever you want with the swiper |
| 21 | + { |
| 22 | + title: "For the Weekend", |
| 23 | + imageUrl: "assets/img/lists/wishlist-2.jpg", |
| 24 | + songs: 4, |
| 25 | + private: false |
25 | 26 | },
|
26 |
| - }; |
27 |
| - |
28 |
| - customPaginationNumbers2 = { |
29 |
| - pager: true, |
30 |
| - autoplay: 2000, |
31 |
| - paginationClickable: true, |
32 |
| - paginationBulletRender: (index, className) => { |
33 |
| - return '<span class="custom-pagination-2 ' + className + '">' + (index + 1) + '</span>'; |
34 |
| - } |
35 |
| - }; |
36 |
| - |
37 |
| - customPaginationIcons = { |
38 |
| - pager: true, |
39 |
| - autoplay: 2000, |
40 |
| - paginationClickable: true, |
41 |
| - paginationBulletRender: (index, className) => { |
42 |
| - return '<span class="custom-pagination-3 ' + 'bullet-icon-' + (index + 1) + ' ' + className + '"></span></span>'; |
| 27 | + { |
| 28 | + title: "Family Time", |
| 29 | + imageUrl: "assets/img/lists/wishlist-3.jpg", |
| 30 | + songs: 5, |
| 31 | + private: true |
| 32 | + }, |
| 33 | + { |
| 34 | + title: "My Trip", |
| 35 | + imageUrl: "assets/img/lists/wishlist-4.jpg", |
| 36 | + songs: 12, |
| 37 | + private: true |
43 | 38 | }
|
44 |
| - }; |
45 |
| - |
46 |
| - slides = [{ |
47 |
| - title: "Dream's Adventure", |
48 |
| - imageUrl: "assets/img/lists/wishlist-1.jpg", |
49 |
| - songs: 2, |
50 |
| - private: false |
51 |
| - }, |
52 |
| - { |
53 |
| - title: "For the Weekend", |
54 |
| - imageUrl: "assets/img/lists/wishlist-2.jpg", |
55 |
| - songs: 4, |
56 |
| - private: false |
57 |
| - }, |
58 |
| - { |
59 |
| - title: "Family Time", |
60 |
| - imageUrl: "assets/img/lists/wishlist-3.jpg", |
61 |
| - songs: 5, |
62 |
| - private: true |
63 |
| - }, |
64 |
| - { |
65 |
| - title: "My Trip", |
66 |
| - imageUrl: "assets/img/lists/wishlist-4.jpg", |
67 |
| - songs: 12, |
68 |
| - private: true |
69 |
| - } |
70 | 39 | ]
|
71 | 40 |
|
72 |
| - onSlideChanged() { |
73 |
| - let currentIndex = this.slider.getActiveIndex(); |
74 |
| - console.log("Slide changed! Current index is", currentIndex); |
75 |
| - } |
76 |
| - |
77 |
| - constructor(public navCtrl: NavController, public alertCtrl: AlertController) { |
78 |
| - this.options = this.customPaginationNumbers; |
79 |
| - } |
| 41 | + constructor(public navCtrl: NavController) { } |
80 | 42 |
|
81 |
| - pagination = 'pagination-numbers'; |
| 43 | + ngAfterViewInit() { |
| 44 | + this.sliderOne.paginationBulletRender = (index, className) => { |
| 45 | + return '<span class="custom-pagination ' + className + '">' + (index + 1) + '</span>'; |
| 46 | + }; |
82 | 47 |
|
83 |
| - changeSlideStyle() { |
84 |
| - this.showSlide = false; |
85 |
| - switch (this.pagination) { |
86 |
| - case 'pagination-numbers': |
87 |
| - this.options = this.customPaginationNumbers; |
88 |
| - break; |
89 |
| - case 'pagination-numbers-2': |
90 |
| - this.options = this.customPaginationNumbers2; |
91 |
| - break; |
92 |
| - case 'pagination-icons': |
93 |
| - this.options = this.customPaginationIcons; |
94 |
| - break; |
| 48 | + this.sliderTwo.paginationBulletRender = (index, className) => { |
| 49 | + return '<span class="custom-pagination-2 ' + className + '">' + (index + 1) + '</span>'; |
95 | 50 | }
|
96 | 51 |
|
97 |
| - // Hack just to make the styles change. Without it, changing options dinamically won't work. |
98 |
| - // NOTE: You DON'T need to do this if you are using only one type of slider. |
99 |
| - setTimeout(() => this.showSlide = true, 10); |
| 52 | + this.sliderThree.paginationBulletRender = (index, className) => { |
| 53 | + return '<span class="custom-pagination-3 ' + 'bullet-icon-' + (index + 1) + ' ' + className + '"></span></span>'; |
| 54 | + } |
100 | 55 | }
|
101 | 56 | }
|
0 commit comments