test(tabs): add change and ViewChild example

Closes #895
This commit is contained in:
Adam Bradley
2016-01-09 21:45:55 -06:00
parent d4cf6d83f2
commit 4d0d2a5d4d

View File

@ -1,6 +1,7 @@
import {ViewChild} from 'angular2/core';
import {RouteConfig, Location} from 'angular2/router';
import {App, Page, NavController, Modal, ViewController} from 'ionic/ionic';
import {App, Page, NavController, Modal, ViewController, Tabs} from 'ionic/ionic';
@Page({
@ -57,10 +58,24 @@ class ChatPage {
templateUrl: './tabs.html'
})
class TabsPage {
@ViewChild(Tabs) tabs: Tabs;
constructor(private nav: NavController) {
this.tab1Root = Tab1Page1
this.tab2Root = Tab2Page1
this.tab3Root = Tab3Page1
this.tab1Root = Tab1Page1;
this.tab2Root = Tab2Page1;
this.tab3Root = Tab3Page1;
}
ngAfterViewInit() {
this.tabs.change.subscribe(tab => {
console.log('tabs.change.subscribe', tab.index);
});
}
onTabChange() {
// wired up through the template
// <ion-tabs (change)="onTabChange()">
console.log('onTabChange');
}
chat() {
@ -68,10 +83,6 @@ class TabsPage {
let modal = Modal.create(ChatPage);
this.nav.present(modal);
}
onTabChange() {
console.log('onTabChange');
}
}
@ -86,19 +97,25 @@ class TabsPage {
'<ion-content padding>' +
'<p><button id="goToTab1Page2" (click)="push()">Go to Tab 1, Page 2</button></p>' +
'<p><button (click)="logout()">Logout</button></p>' +
'<p><button (click)="favoritesTab()">Favorites Tab</button></p>' +
'<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>' +
'<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>' +
'</ion-content>'
})
class Tab1Page1 {
constructor(nav: NavController) {
constructor(nav: NavController, tabs: Tabs) {
this.nav = nav;
this.tabs = tabs;
}
push() {
this.nav.push(Tab1Page2)
}
favoritesTab() {
this.tabs.select(1);
}
logout() {
this.nav.rootNav.setRoot(SignIn, null, { animate: true, direction: 'back' });
}