import {Component, Type} from 'angular2/core';
import {App, NavController, Alert} from 'ionic-angular';
import {Page, Config, IonicApp} from 'ionic-angular';
import {NavParams, ViewController, IONIC_DIRECTIVES} from 'ionic-angular';;
@Component({
selector: 'my-cmp',
template: `
My Custom Component Test
`,
directives: [IONIC_DIRECTIVES]
})
class MyCmpTest{}
@Page({
template: `
{{title}}
S1g
{{title}}
Push to FullPage
Push to PrimaryHeaderPage
Push to AnotherPage
Text Input
Push FullPage w/ [navPush] array
Push w/ [navPush] and [navParams]
Push w/ [navPush] array and string view name
Push w/ [navPush] and [navParams]
setPages() (Go to PrimaryHeaderPage)
setRoot(PrimaryHeaderPage) (Go to PrimaryHeaderPage)
Pop
View Dismiss
New push during transition
New pop during transition
Reload
Page {{i}}
`,
directives: [MyCmpTest]
})
class FirstPage {
pushPage;
title = 'First Page';
pages: Array = [];
constructor(
private nav: NavController,
private view: ViewController
) {
this.pushPage = FullPage;
for (var i = 1; i <= 50; i++) {
this.pages.push(i);
}
}
setPages() {
let items = [
{ page: PrimaryHeaderPage }
];
this.nav.setPages(items);
}
setRoot() {
this.nav.setRoot(PrimaryHeaderPage);
}
pushPrimaryHeaderPage() {
this.nav.push(PrimaryHeaderPage);
}
pushFullPage() {
this.nav.push(FullPage, { id: 8675309, myData: [1, 2, 3, 4] });
}
pushAnother() {
this.nav.push(AnotherPage);
}
quickPush() {
this.nav.push(AnotherPage);
setTimeout(() => {
this.nav.push(PrimaryHeaderPage);
}, 150);
}
quickPop() {
this.nav.push(AnotherPage);
setTimeout(() => {
this.nav.remove(1, 1);
}, 250);
}
viewDismiss() {
this.view.dismiss();
}
reload() {
window.location.reload();
}
}
@Page({
template: `
Full page
This page does not have a nav bar!
Pop
Push to PrimaryHeaderPage
Push to AnotherPage
Push to FirstPage
Pop with NavPop (Go back to 1st)
setPages() (Go to PrimaryHeaderPage, FirstPage 1st in history)
Present Alert
`
})
class FullPage {
constructor(
private nav: NavController,
private params: NavParams
) {}
setPages() {
let items = [
{ page: FirstPage },
{ page: PrimaryHeaderPage }
];
this.nav.setPages(items);
}
pushPrimaryHeaderPage() {
this.nav.push(PrimaryHeaderPage);
}
pushAnother() {
this.nav.push(AnotherPage);
}
pushFirstPage() {
this.nav.push(FirstPage);
}
presentAlert() {
let alert = Alert.create();
alert.setTitle('Hello Alert');
alert.setMessage('Dismiss this alert, then pop one page');
alert.addButton({
text: 'Dismiss',
role: 'cancel',
handler: () => {
// overlays are added and removed from the root navigation
// ensure you using the root navigation, and pop this alert
// when the alert is done animating out, then pop off the active page
this.nav.rootNav.pop().then(() => {
this.nav.rootNav.pop();
});
// by default an alert will dismiss itself
// however, we don't want to use the default
// but rather fire off our own pop navigation
// return false so it doesn't pop automatically
return false;
}
});
this.nav.present(alert);
}
}
@Page({
template: `
Primary Color Page Header
S1g
Pop
Push to AnotherPage
Push to FullPage
setRoot(AnotherPage)
Pop to root
Insert first page into history before this
Remove second page in history
`
})
class PrimaryHeaderPage {
constructor(
private nav: NavController,
private viewCtrl: ViewController
) {}
onPageWillEnter() {
this.viewCtrl.setBackButtonText('Previous');
}
pushAnother() {
this.nav.push(AnotherPage);
}
pushFullPage() {
this.nav.push(FullPage, { id: 8675309, myData: [1, 2, 3, 4] });
}
insert() {
this.nav.insert(2, FirstPage);
}
removeSecond() {
this.nav.remove(1);
}
setRoot() {
this.nav.setRoot(AnotherPage);
}
}
@Page({
template: `
Another Page Header
Text Input
Back button hidden w/ ion-navbar hideBackButton
Pop
Push to FullPage
Push to PrimaryHeaderPage
Push to FirstPage
setRoot(FirstPage)
Toggle hideBackButton
Set Back Button Text
`
})
class AnotherPage {
bbHideToggleVal = false;
bbCount = 0;
constructor(
private nav: NavController,
private viewCtrl: ViewController
) {
console.log('Page, AnotherPage, constructor', this.viewCtrl.id);
}
pushFullPage() {
this.nav.push(FullPage);
}
pushPrimaryHeaderPage() {
this.nav.push(PrimaryHeaderPage);
}
pushFirstPage() {
this.nav.push(FirstPage);
}
setRoot() {
this.nav.setRoot(FirstPage);
}
toggleBackButton() {
this.bbHideToggleVal = !this.bbHideToggleVal
this.viewCtrl.showBackButton(this.bbHideToggleVal);
}
setBackButtonText() {
let backButtonText = 'Messages';
if (this.bbCount > 0) {
backButtonText += ` (${this.bbCount})`;
}
this.viewCtrl.setBackButtonText(backButtonText);
++this.bbCount;
}
onPageWillEnter() {
console.log('Page, AnotherPage, onPageWillEnter', this.viewCtrl.id);
}
onPageDidEnter() {
console.log('Page, AnotherPage, onPageDidEnter', this.viewCtrl.id);
}
onPageWillLeave() {
console.log('Page, AnotherPage, onPageWillLeave', this.viewCtrl.id);
}
onPageDidLeave() {
console.log('Page, AnotherPage, onPageDidLeave', this.viewCtrl.id);
}
onPageWillUnload() {
console.log('Page, AnotherPage, onPageWillUnload', this.viewCtrl.id);
}
onPageDidUnload() {
console.log('Page, AnotherPage, onPageDidUnload', this.viewCtrl.id);
}
ngOnDestroy() {
console.log('Page, AnotherPage, ngOnDestroy', this.viewCtrl.id);
}
}
@App({
pages: [FirstPage, FullPage, PrimaryHeaderPage, AnotherPage],
template: ` `,
host: {
'[class.is-change-detecting]': 'isChangeDetecting'
}
})
class E2EApp {
root;
constructor() {
this.root = FirstPage;
}
get isChangeDetecting() {
console.log('isChangeDetecting');
return true;
}
}