Files
Brandy Carney 05c7b8f0d7 docs(demos): update API demos so they all have ion-navs
- add spacing between imports
- alphabetize imports
- removed app.html files in favor of an inline ion-nav
- cleaned up config demo so it uses proper syntax
- use file name main.html for the first page for the demo
- name the app ApiDemoApp and first page ApiDemoPage
- replace the ion-toolbars with ion-navbars

closes #7019
closes driftyco/ionic-site#647
2016-06-22 14:45:49 -04:00

76 lines
1.3 KiB
TypeScript

import { Component, ViewChild } from '@angular/core';
import { Events, ionicBootstrap, Nav } from 'ionic-angular';
@Component({
templateUrl: 'login.html'
})
class Login {
user = {
name: "Administrator",
username: "admin"
};
constructor(private events: Events) {}
login() {
this.events.publish('user:login');
}
}
@Component({
templateUrl: 'logout.html'
})
class Logout {
constructor(private events: Events) {}
logout() {
this.events.publish('user:logout');
}
}
@Component({
templateUrl: 'app.html'
})
class ApiDemoApp {
@ViewChild(Nav) nav: Nav;
root = Login;
loggedIn = false;
loggedInPages = [
{ title: 'Logout', component: Logout }
];
loggedOutPages = [
{ title: 'Login', component: Login }
];
constructor(private events: Events) {
this.listenToLoginEvents();
}
openPage(menu, page) {
// find the nav component and set what the root page should be
// reset the nav to remove previous pages and only have this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
}
listenToLoginEvents() {
this.events.subscribe('user:login', () => {
this.loggedIn = true;
});
this.events.subscribe('user:logout', () => {
this.loggedIn = false;
});
}
}
ionicBootstrap(ApiDemoApp);