forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.component.ts
More file actions
70 lines (55 loc) · 1.29 KB
/
app.component.ts
File metadata and controls
70 lines (55 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Component, ViewChild } from '@angular/core';
import { Events, Nav } from 'ionic-angular';
@Component({
templateUrl: 'login.html'
})
export class Login {
user = {
name: 'Administrator',
username: 'admin'
};
constructor(private events: Events) {}
login() {
this.events.publish('user:login');
}
}
@Component({
templateUrl: 'logout.html'
})
export class Logout {
constructor(private events: Events) {}
logout() {
this.events.publish('user:logout');
}
}
@Component({
templateUrl: 'app.html'
})
export 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;
});
}
}