forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.component.ts
46 lines (41 loc) · 1.2 KB
/
app.component.ts
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
// #docplaster
// #docregion
// #docregion imports
import { Component, Inject } from '@angular/core';
import { APP_CONFIG, AppConfig } from './app.config';
import { UserService } from './user.service';
// #enddocregion imports
@Component({
selector: 'app-root',
template: `
<h1>{{title}}</h1>
<app-car></app-car>
<app-injectors></app-injectors>
<app-tests></app-tests>
<h2>User</h2>
<p id="user">
{{userInfo}}
<button (click)="nextUser()">Next User</button>
<p>
<app-heroes id="authorized" *ngIf="isAuthorized"></app-heroes>
<app-heroes id="unauthorized" *ngIf="!isAuthorized"></app-heroes>
<app-providers></app-providers>
`
})
export class AppComponent {
title: string;
// #docregion ctor
constructor(
@Inject(APP_CONFIG) config: AppConfig,
private userService: UserService) {
this.title = config.title;
}
// #enddocregion ctor
get isAuthorized() { return this.user.isAuthorized; }
nextUser() { this.userService.getNewUser(); }
get user() { return this.userService.user; }
get userInfo() {
return `Current user, ${this.user.name}, is ` +
`${this.isAuthorized ? '' : 'not'} authorized. `;
}
}