Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 537a5c9

Browse files
committed
Change appConfig to use a class (and still useValue)
1 parent 835cfbb commit 537a5c9

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

public/docs/_examples/dependency-injection/dart/lib/app_component.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import 'providers_component.dart';
3737
providers: const [
3838
Logger,
3939
UserService,
40-
const Provider(appConfig, useValue: config1)]
40+
const Provider(AppConfig, useValue: config1)]
4141
// #enddocregion providers
4242
)
4343
class AppComponent {
4444
final UserService _userService;
4545
final String title;
4646

4747
//#docregion ctor
48-
AppComponent(@Inject(appConfig) Map config, this._userService) :
49-
title = config['title'];
48+
AppComponent(AppConfig config, this._userService)
49+
: title = config.title;
5050
// #enddocregion ctor
5151

5252
bool get isAuthorized {

public/docs/_examples/dependency-injection/dart/lib/app_component_2.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import 'logger_service.dart';
2222
providers: const [
2323
Logger,
2424
// #docregion provider-config
25-
const Provider(appConfig, useValue: config1)
25+
const Provider(AppConfig, useValue: config1)
2626
])
2727
class AppComponent {
2828
final String title;
2929

3030
// #docregion ctor
31-
AppComponent(@Inject(appConfig) Map config)
32-
: title = config['title'];
31+
AppComponent(AppConfig config)
32+
: title = config.title;
3333
// #enddocregion
3434
}

public/docs/_examples/dependency-injection/dart/lib/app_config.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// #docregion token
33
import 'package:angular2/core.dart';
44

5-
const appConfig = const OpaqueToken('app.config');
6-
// #enddocregion token
7-
85
//#docregion config
9-
const config1 = const <String, String>{
10-
'apiEndpoint': 'api.heroes.com',
11-
'title': 'Dependency Injection'
12-
};
6+
@Injectable()
7+
class AppConfig {
8+
final apiEndpoint;
9+
final String title;
10+
11+
const AppConfig(this.apiEndpoint, this.title);
12+
}
13+
14+
const config1 = const AppConfig('api.heroes.com', 'Dependency Injection');
1315
//#enddocregion config

public/docs/_examples/dependency-injection/dart/lib/providers_component.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,21 @@ class ProviderComponent8 {
221221
selector: 'provider-9',
222222
template: '{{log}}',
223223
// #docregion providers-9
224-
providers: const [const Provider(appConfig, useValue: config1)]
224+
providers: const [const Provider(AppConfig, useValue: config1)]
225225
// . . .
226226
// #enddocregion providers-9
227227
)
228228
class ProviderComponent9 implements OnInit {
229-
final Map<String, String> _config;
229+
AppConfig _config;
230230
String log;
231231

232232
// #docregion providers-9
233-
ProviderComponent9(@Inject(appConfig) this._config);
233+
ProviderComponent9(AppConfig this._config);
234234

235235
// #enddocregion providers-9
236236
@override
237237
void ngOnInit() {
238-
log = 'appConfigToken Application title is ${_config["title"]}';
238+
log = 'appConfigToken Application title is ${_config.title}';
239239
}
240240
}
241241

0 commit comments

Comments
 (0)