From 2295bd9264f3ba8f2ffce7e07fcde1d3fd1ac03a Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 16 Apr 2016 23:09:13 -0500 Subject: [PATCH] test(slides): update to use @ViewChild --- ionic/components/slides/test/basic/index.ts | 28 ++++++++------------- ionic/components/slides/test/intro/index.ts | 4 +-- ionic/components/slides/test/loop/index.ts | 23 ++++++++--------- ionic/components/slides/test/loop/main.html | 2 +- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/ionic/components/slides/test/basic/index.ts b/ionic/components/slides/test/basic/index.ts index 8cb8e990662..3cff96a2544 100644 --- a/ionic/components/slides/test/basic/index.ts +++ b/ionic/components/slides/test/basic/index.ts @@ -1,20 +1,23 @@ -import {App, IonicApp} from 'ionic-angular'; +import {ViewChild} from 'angular2/core'; import {Http} from 'angular2/http'; +import {App, Slides} from 'ionic-angular'; + @App({ templateUrl: 'main.html' }) class MyApp { - constructor(app: IonicApp, http: Http) { - this.app = app; - this.http = http; + mySlideOptions: any; + images: string[] = []; + @ViewChild(Slides) slider: Slides; + constructor(private http: Http) { this.mySlideOptions = { loop: true }; + } - this.images = []; - + ngAfterViewInit() { let tags = "amsterdam"; let FLICKR_API_KEY = '504fd7414f6275eb5b657ddbfba80a2c'; @@ -27,24 +30,15 @@ class MyApp { setTimeout(() => { this.slider.update(); }); + }, (err) => { console.info('Unable to load images'); console.error(err); - }) - } - - ngOnInit() { - setTimeout(() => { - this.slider = this.app.getComponent('slider'); - console.log('Got slider', this.slider); }); } getImageUrl(item) { - return "http://farm"+ item.farm +".static.flickr.com/"+ item.server +"/"+ item.id +"_"+ item.secret + "_z.jpg"; + return `http://farm${item.farm}.static.flickr.com/${item.server}/${item.id}_${item.secret}_z.jpg`; } - doRefresh() { - console.log('DOREFRESH') - } } diff --git a/ionic/components/slides/test/intro/index.ts b/ionic/components/slides/test/intro/index.ts index bf0e0681c97..5599dc454c6 100644 --- a/ionic/components/slides/test/intro/index.ts +++ b/ionic/components/slides/test/intro/index.ts @@ -20,9 +20,7 @@ class IntroPage { startingIndex: number = 1; mySlideOptions; - constructor(nav: NavController) { - this.nav = nav; - + constructor(private nav: NavController) { this.mySlideOptions = { paginationClickable: true, lazyLoading: true, diff --git a/ionic/components/slides/test/loop/index.ts b/ionic/components/slides/test/loop/index.ts index 0161446db78..202dcb8a147 100644 --- a/ionic/components/slides/test/loop/index.ts +++ b/ionic/components/slides/test/loop/index.ts @@ -1,12 +1,16 @@ -import {App, IonicApp} from 'ionic-angular'; +import {ViewChild} from 'angular2/core'; +import {App, Slides} from 'ionic-angular'; @App({ templateUrl: 'main.html' }) class MyApp { - constructor(app: IonicApp) { - this.app = app; + slides: any[]; + @ViewChild('loopSlider') loopSlider: Slides; + startingIndex: number; + myTopSlideOptions: any; + constructor() { this.slides = [ { name: "Slide 1", @@ -22,23 +26,16 @@ class MyApp { } ]; - this.startingIndex = 2; - this.myTopSlideOptions = { - index: this.startingIndex, + initialSlide: 2, loop: true }; + } - onSlideChanged(slider) { + onSlideChanged(slider: Slides) { console.log('Slide changed', slider); console.log("active index", slider.activeIndex); } - ngOnInit() { - setTimeout(() => { - this.slider = this.app.getComponent('loopSlider'); - console.log('Got slider', this.slider); - }); - } } diff --git a/ionic/components/slides/test/loop/main.html b/ionic/components/slides/test/loop/main.html index 01d2a6f6d80..60dd98a9a85 100644 --- a/ionic/components/slides/test/loop/main.html +++ b/ionic/components/slides/test/loop/main.html @@ -1,5 +1,5 @@
- + Loop {{ slide.name }}