Skip to content

Commit

Permalink
test(slides): update to use @ViewChild
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Apr 17, 2016
1 parent 1daa7c5 commit 2295bd9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
28 changes: 11 additions & 17 deletions ionic/components/slides/test/basic/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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')
}
}
4 changes: 1 addition & 3 deletions ionic/components/slides/test/intro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 10 additions & 13 deletions ionic/components/slides/test/loop/index.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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);
});
}
}
2 changes: 1 addition & 1 deletion ionic/components/slides/test/loop/main.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="slides-div">
<ion-slides [options]="myTopSlideOptions" id="loopSlider" (change)="onSlideChanged($event)" pager>
<ion-slides [options]="myTopSlideOptions" #loopSlider (change)="onSlideChanged($event)" pager>
<ion-slide *ngFor="#slide of slides" [ngClass]="slide.class">
Loop {{ slide.name }}
</ion-slide>
Expand Down

0 comments on commit 2295bd9

Please sign in to comment.