forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_component.dart
62 lines (55 loc) · 1.53 KB
/
app_component.dart
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
import 'package:angular2/core.dart';
import 'app_config.dart';
import 'car/car_component.dart';
import 'heroes/heroes_component.dart';
import 'logger_service.dart';
import 'user_service.dart';
import 'injector_component.dart';
import 'test_component.dart';
import 'providers_component.dart';
@Component(
selector: 'my-app',
template: '''
<h1>{{title}}</h1>
<my-car></my-car>
<my-injectors></my-injectors>
<my-tests></my-tests>
<h2>User</h2>
<p id="user">
{{userInfo}}
<button (click)="nextUser()">Next User</button>
<p>
<my-heroes id="authorized" *ngIf="isAuthorized"></my-heroes>
<my-heroes id="unauthorized" *ngIf="!isAuthorized"></my-heroes>''',
directives: const [
CarComponent,
HeroesComponent,
InjectorComponent,
TestComponent,
ProvidersComponent
],
// #docregion providers
providers: const [
Logger, UserService,
const Provider(APP_CONFIG, useFactory: heroDiConfigFactory)]
// #enddocregion providers
)
class AppComponent {
final UserService _userService;
final String title;
// #docregion ctor
AppComponent(@Inject(APP_CONFIG) AppConfig config, this._userService)
: title = config.title;
// #enddocregion ctor
bool get isAuthorized {
return user.isAuthorized;
}
void nextUser() {
_userService.getNewUser();
}
User get user {
return _userService.user;
}
String get userInfo => 'Current user, ${user.name}, is' +
(isAuthorized ? '' : ' not') + ' authorized. ';
}