import { NgModule, Component, ViewChild } from '@angular/core';
import { App, AlertController, Content, DeepLinkConfig, IonicApp, IonicModule, NavController, NavParams, ViewController } from '../../../..';
@Component({
selector: 'my-cmp',
template: `
My Custom Component Test
`
})
export class MyCmpTest {}
@Component({
template: `
{{title}}
S1g
{{title}}
Push to FullPage
Push to PrimaryHeaderPage
Push to AnotherPage
Text Input
Push FullPage w/ navPush="FullPage"
Push w/ [navPush] and [navParams]
Push w/ [navPush] and string view name
setPages() (Go to PrimaryHeaderPage)
setRoot(PrimaryHeaderPage) (Go to PrimaryHeaderPage)
Pop
Toggle Can Leave
View Dismiss
New push during transition
New pop during transition
Reload
Scroll to bottom
Page {{i}}
Scroll to top
`
})
export class FirstPage {
pushPage = FullPage;
title = 'First Page';
pages: Array = [];
@ViewChild(Content) content: Content;
canLeave = true;
constructor(
public navCtrl: NavController,
public viewCtrl: ViewController,
public alertCtrl: AlertController
) {}
ionViewDidLoad() {
console.log('ionViewDidLoad, FirstPage');
for (var i = 1; i <= 50; i++) {
this.pages.push(i);
}
}
ionViewWillEnter() {
console.log('ionViewWillEnter, FirstPage', this.viewCtrl.id);
}
ionViewDidEnter() {
console.log('ionViewDidEnter, FirstPage', this.viewCtrl.id);
}
ionViewWillLeave() {
console.log('ionViewWillLeave, FirstPage', this.viewCtrl.id);
}
ionViewDidLeave() {
console.log('ionViewDidLeave, FirstPage', this.viewCtrl.id);
}
ionViewWillUnload() {
console.log('ionViewWillUnload, FirstPage', this.viewCtrl.id);
}
ionViewCanLeave() {
if (this.canLeave) {
return true;
}
let alert = this.alertCtrl.create();
alert.setMessage('You can check-out any time you like, but you can never leave.');
alert.addButton({ text: 'Umm, ok', role: 'cancel', });
alert.present();
return false;
}
setPages() {
let items = [
{ page: PrimaryHeaderPage }
];
this.navCtrl.setPages(items);
}
setRoot() {
this.navCtrl.setRoot(PrimaryHeaderPage);
}
pushPrimaryHeaderPage() {
this.navCtrl.push(PrimaryHeaderPage).then(() => {}, (rejectReason: string) => {
});
}
pushFullPage() {
this.navCtrl.push(FullPage, { id: 8675309, myData: [1, 2, 3, 4] }).catch(() => {
});
}
pushAnother() {
this.navCtrl.push(AnotherPage).catch(() => {
});
}
quickPush() {
this.navCtrl.push(AnotherPage).catch(() => {
});
setTimeout(() => {
this.navCtrl.push(PrimaryHeaderPage).catch(() => {
});
}, 150);
}
quickPop() {
this.navCtrl.push(AnotherPage).catch(() => {
});
setTimeout(() => {
this.navCtrl.remove(1, 1).catch(() => {
});
}, 250);
}
viewDismiss() {
this.viewCtrl.dismiss();
}
reload() {
window.location.reload();
}
scrollToTop() {
this.content.scrollToTop();
}
scrollToBottom() {
this.content.scrollToBottom(1000);
}
}
@Component({
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
`
})
export class FullPage {
constructor(
public navCtrl: NavController,
public viewCtrl: ViewController,
public app: App,
public alertCtrl: AlertController,
public params: NavParams
) {}
ionViewDidLoad() {
console.log('ionViewDidLoad, FullPage', this.viewCtrl.id);
}
ionViewWillEnter() {
console.log('ionViewWillEnter, FullPage', this.viewCtrl.id);
}
ionViewDidEnter() {
console.log('ionViewDidEnter, FullPage', this.viewCtrl.id);
}
ionViewWillLeave() {
console.log('ionViewWillLeave, FullPage', this.viewCtrl.id);
}
ionViewDidLeave() {
console.log('ionViewDidLeave, FullPage', this.viewCtrl.id);
}
ionViewWillUnload() {
console.log('ionViewWillUnload, FullPage', this.viewCtrl.id);
}
setPages() {
let items = [
{ page: FirstPage },
{ page: PrimaryHeaderPage }
];
this.navCtrl.setPages(items);
}
pushPrimaryHeaderPage() {
this.navCtrl.push(PrimaryHeaderPage);
}
pushAnother() {
this.navCtrl.push(AnotherPage);
}
pushFirstPage() {
this.navCtrl.push(FirstPage);
}
presentAlert() {
let alert = this.alertCtrl.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 app root's portal
// in the example below, alert.dismiss() dismisses the alert
// from the app root portal, and once it's done transitioning out,
// this the active page is popped from the nav
alert.dismiss().then(() => {
this.navCtrl.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;
}
});
alert.present();
}
}
@Component({
template: `
Primary Color Page Header
S1g
{{subheader}}
Pop
Push to AnotherPage
Push to FullPage
setRoot(AnotherPage)
Pop to root
Insert first page into history before this
Remove second page in history
fixed button (alert)
I'm a sub footer!
Footer
`
})
export class PrimaryHeaderPage {
subheader: string;
constructor(
public navCtrl: NavController,
public alertCtrl: AlertController,
public viewCtrl: ViewController
) {}
ionViewDidLoad() {
console.log('ionViewDidLoad, PrimaryHeaderPage', this.viewCtrl.id);
}
ionViewWillEnter() {
console.log('ionViewWillEnter, PrimaryHeaderPage', this.viewCtrl.id);
this.viewCtrl.setBackButtonText('Previous');
this.subheader = 'I\'m a sub header!';
}
ionViewDidEnter() {
console.log('ionViewDidEnter, PrimaryHeaderPage', this.viewCtrl.id);
}
ionViewWillLeave() {
console.log('ionViewWillLeave, PrimaryHeaderPage', this.viewCtrl.id);
}
ionViewDidLeave() {
console.log('ionViewDidLeave, PrimaryHeaderPage', this.viewCtrl.id);
}
ionViewWillUnload() {
console.log('ionViewWillUnload, PrimaryHeaderPage', this.viewCtrl.id);
}
pushAnother() {
this.navCtrl.push(AnotherPage);
}
pushFullPage() {
this.navCtrl.push(FullPage, { id: 8675309, myData: [1, 2, 3, 4] });
}
insert() {
this.navCtrl.insert(2, FirstPage);
}
removeSecond() {
this.navCtrl.remove(1);
}
setRoot() {
this.navCtrl.setRoot(AnotherPage);
}
presentAlert() {
let alert = this.alertCtrl.create();
alert.setTitle('Hello Alert');
alert.addButton({ text: 'Dismiss', role: 'cancel', });
alert.present();
}
}
@Component({
template: `
Another Page Header
I'm a sub header in the content!
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
I'm a sub footer in the content!
And I'm a sub footer in the content too!
Another Page Footer
`
})
export class AnotherPage {
bbHideToggleVal = false;
bbCount = 0;
constructor(
public navCtrl: NavController,
public viewCtrl: ViewController
) { }
ionViewDidLoad() {
console.log('ionViewDidLoad, AnotherPage', this.viewCtrl.id);
}
ionViewWillEnter() {
console.log('ionViewWillEnter, AnotherPage', this.viewCtrl.id);
}
ionViewDidEnter() {
console.log('ionViewDidEnter, AnotherPage', this.viewCtrl.id);
}
ionViewWillLeave() {
console.log('ionViewWillLeave, AnotherPage', this.viewCtrl.id);
}
ionViewDidLeave() {
console.log('ionViewDidLeave, AnotherPage', this.viewCtrl.id);
}
ionViewWillUnload() {
console.log('ionViewWillUnload, AnotherPage', this.viewCtrl.id);
}
pushFullPage() {
this.navCtrl.push(FullPage);
}
pushPrimaryHeaderPage() {
this.navCtrl.push(PrimaryHeaderPage);
}
pushFirstPage() {
this.navCtrl.push(FirstPage);
}
setRoot() {
this.navCtrl.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;
}
}
@Component({
template: ` `
})
export class E2EApp {
root = FirstPage;
}
export const deepLinkConfig: DeepLinkConfig = {
links: [
{ component: FirstPage, name: 'first-page' },
{ component: AnotherPage, name: 'another-page' },
{ component: MyCmpTest, name: 'tab1-page1' },
{ component: FullPage, name: 'full-page', defaultHistory: ['first-page', 'another-page'] },
{ component: PrimaryHeaderPage, name: 'primary-header-page', defaultHistory: ['first-page', 'full-page'] },
]
};
@NgModule({
declarations: [
E2EApp,
FirstPage,
AnotherPage,
MyCmpTest,
FullPage,
PrimaryHeaderPage
],
imports: [
IonicModule.forRoot(E2EApp, null, deepLinkConfig)
],
bootstrap: [IonicApp],
entryComponents: [
E2EApp,
FirstPage,
AnotherPage,
FullPage,
PrimaryHeaderPage
]
})
export class AppModule {}