diff --git a/demos/events/index.ts b/demos/events/index.ts new file mode 100644 index 0000000000..e84d7d0a5d --- /dev/null +++ b/demos/events/index.ts @@ -0,0 +1,68 @@ +import {App, IonicApp, Page, Events} from 'ionic/ionic'; + +@Page({templateUrl: 'login.html'}) +class Login { + constructor(events: Events) { + this.events = events; + + this.user = { + name: "Administrator", + username: "admin" + }; + } + + login() { + this.events.publish('user:login'); + } + + +} + +@Page({templateUrl: 'logout.html'}) +class Logout { + constructor(events: Events) { + this.events = events; + } + + logout() { + this.events.publish('user:logout'); + } +} + +@App({ + templateUrl: 'main.html' +}) +class ApiDemoApp { + constructor(app: IonicApp, events: Events) { + this.app = app; + this.events = events; + + this.rootView = Login; + this.loggedIn = false; + + this.pages = [ + { title: 'Logout', component: Logout, showLoggedIn: true }, + { title: 'Login', component: Login, showLoggedIn: false }, + ]; + + 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 + let nav = this.app.getComponent('nav'); + nav.setRoot(page.component); + } + + listenToLoginEvents() { + this.events.subscribe('user:login', () => { + this.loggedIn = true; + }); + + this.events.subscribe('user:logout', () => { + this.loggedIn = false; + }); + } +} diff --git a/demos/events/login.html b/demos/events/login.html new file mode 100644 index 0000000000..515e289c15 --- /dev/null +++ b/demos/events/login.html @@ -0,0 +1,31 @@ + + + + + + + + Events + + + + + Login + Click the login button to use the credentials below. Then, toggle the menu to see the menu items change. + + + + Name + + + + Username + + + + + + Login + Toggle Menu + + diff --git a/demos/events/logout.html b/demos/events/logout.html new file mode 100644 index 0000000000..0d5c4ac07d --- /dev/null +++ b/demos/events/logout.html @@ -0,0 +1,20 @@ + + + + + + + + Events + + + + + Logout + Click the logout button to logout. Then, toggle the menu to see the menu items change. + + + Logout + Toggle Menu + + diff --git a/demos/events/main.html b/demos/events/main.html new file mode 100644 index 0000000000..3704fc995d --- /dev/null +++ b/demos/events/main.html @@ -0,0 +1,27 @@ + + + + Left Menu + + + + + + + Welcome, Administrator! + + + {{p.title}} + + + + Close Menu + + + + + + + + + diff --git a/ionic/util/events.ts b/ionic/util/events.ts index 3a8055b373..2f61ba55d1 100644 --- a/ionic/util/events.ts +++ b/ionic/util/events.ts @@ -17,6 +17,7 @@ * }); * * ``` + * @demo /docs/v2/demos/events/ */ export class Events { private _channels: Array = [];
Click the login button to use the credentials below. Then, toggle the menu to see the menu items change.
Click the logout button to logout. Then, toggle the menu to see the menu items change.