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

Commit 5f40a6e

Browse files
committed
fix text to reflect new code
1 parent 537a5c9 commit 5f40a6e

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import 'logger_service.dart';
2121
],
2222
providers: const [
2323
Logger,
24-
// #docregion provider-config
2524
const Provider(AppConfig, useValue: config1)
2625
])
2726
class AppComponent {

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

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

5-
//#docregion config
5+
//#docregion const-class
66
@Injectable()
77
class AppConfig {
88
final apiEndpoint;
99
final String title;
1010

1111
const AppConfig(this.apiEndpoint, this.title);
1212
}
13+
//#enddocregion const-class
1314

15+
//#docregion const-object
1416
const config1 = const AppConfig('api.heroes.com', 'Dependency Injection');
15-
//#enddocregion config
17+
//#enddocregion const-object

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,15 @@ class ProviderComponent8 {
221221
selector: 'provider-9',
222222
template: '{{log}}',
223223
// #docregion providers-9
224-
providers: const [const Provider(AppConfig, useValue: config1)]
225-
// . . .
224+
providers: const [const Provider(AppConfig, useValue: config1)]
226225
// #enddocregion providers-9
227226
)
228227
class ProviderComponent9 implements OnInit {
229228
AppConfig _config;
230229
String log;
231230

232-
// #docregion providers-9
233231
ProviderComponent9(AppConfig this._config);
234232

235-
// #enddocregion providers-9
236233
@override
237234
void ngOnInit() {
238235
log = 'appConfigToken Application title is ${_config.title}';

public/docs/dart/latest/guide/dependency-injection.jade

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,34 +189,41 @@ code-example(format, language="html").
189189
+includeShared('{ts}', 'providers-aliased-1')
190190
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-6a')(format=".")
191191
+includeShared('{ts}', 'providers-aliased-2')
192-
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-6b')(format=".")
192+
- var stylePattern = { otl: /(useExisting.*\))/gm };
193+
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-6b','', stylePattern)(format=".")
193194

194195
+includeShared('{ts}', 'providers-value-1')
195196
:marked
196197
By specifying a `useValue` parameter to `Provider`,
197198
we can provide objects directly,
198199
instead of asking the injector to create an instance of a class.
199200

200-
In Dart code, `useValue` is handy for passing configuration information,
201-
often using literals such as strings, lists, and maps.
201+
Because Dart annotations must be compile-time constants,
202+
`useValue` is often used with string or list literals.
203+
However, you can also use `useValue` with constant objects.
202204

203-
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-usevalue')(format=".")
205+
To create a class that can provide constant objects,
206+
make sure all its instance variables are `final`,
207+
and give it a `const` constructor:
208+
209+
+makeExample('dependency-injection/dart/lib/app_config.dart','const-class','lib/app_config.dart (excerpt)')(format='.')
210+
211+
:marked
212+
To create a constant instance of that class, use `const` instead of `new`:
213+
214+
+makeExample('dependency-injection/dart/lib/app_config.dart','const-object','lib/app_config.dart (excerpt)')(format='.')
215+
216+
:marked
217+
Then specify the object using the `useValue` argument to `Provider`:
218+
219+
- var stylePattern = { otl: /(useValue.*\))/gm };
220+
+makeExample('dependency-injection/dart/lib/providers_component.dart','providers-9','', stylePattern)(format='.')
204221

205222
:marked
206223
See more `useValue` examples in the
207224
[Non-class dependencies](#non-class-dependencies) and
208225
[OpaqueToken](#opaquetoken) sections.
209226

210-
.callout.is-helpful
211-
header Dart difference: Creating objects
212-
:marked
213-
TypeScript Angular code sometimes uses `useValue` to pass in
214-
objects created without using a constructor.
215-
Dart doesn't support instantiating random objects outside of constructors.
216-
Another reason `useValue` is less common in Dart is that
217-
the argument's value must be constant
218-
(because Dart annotations must have constant values).
219-
220227
+includeShared('{ts}', 'providers-factory-1')
221228
+makeExample('dependency-injection/dart/lib/heroes/hero_service.dart','internals', 'lib/heroes/hero_service.dart (excerpt)')(format='.')
222229
+includeShared('{ts}', 'providers-factory-2')
@@ -225,7 +232,7 @@ code-example(format, language="html").
225232
+makeExample('dependency-injection/dart/lib/heroes/hero_service_provider.dart','provider', 'lib/heroes/hero_service_provider.dart (excerpt)')(format='.')
226233
+includeShared('{ts}', 'providers-factory-4')
227234
+includeShared('{ts}', 'providers-factory-5')
228-
- var stylePattern = { pnk: /(providers.*),$/gm };
235+
- var stylePattern = { otl: /(providers.*),$/gm };
229236
+makeTabs(
230237
`dependency-injection/dart/lib/heroes/heroes_component.dart,
231238
dependency-injection/dart/lib/heroes/heroes_component_1.dart`,
@@ -247,6 +254,7 @@ code-example(format, language="html").
247254
every class implicitly defines an interface,
248255
so interface names are just class names.
249256
+includeShared('{ts}', 'tokens-non-class-deps-1')
257+
[PENDING: fix!!]
250258
+makeExample('dependency-injection/dart/lib/app_config.dart','config','lib/app_config.dart (excerpt)')(format='.')
251259
:marked
252260
We know we can register an object with a [value provider](#value-provider).

public/docs/ts/latest/guide/dependency-injection.jade

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,13 @@ code-example(format, language="html").
637637
### Value providers
638638
// #enddocregion providers-value-1
639639
640-
// #docregion providers-value-2
640+
// Typescript only
641641
:marked
642642
Sometimes it's easier to provide a ready-made object rather than ask the injector to create it from a class.
643643
+makeExample('dependency-injection/ts/app/providers.component.ts','silent-logger')(format=".")
644-
// #enddocregion providers-value-2
645-
// #docregion providers-value-3
646644
:marked
647645
Then we register a provider with the `useValue` option,
648646
which makes this object play the logger role.
649-
// #enddocregion providers-value-3
650647
+makeExample('dependency-injection/ts/app/providers.component.ts','providers-7')(format=".")
651648

652649
// #docregion providers-factory-1
@@ -753,7 +750,7 @@ code-example(format, language="html").
753750
754751
// #docregion tokens-non-class-deps-1
755752
- var lang = current.path[1]
756-
- var objectexamples = lang == 'dart' ? 'an object, such as a string, list, or map literal' : 'a string, a function, or an object'
753+
- var objectexamples = lang == 'dart' ? 'a string or list literal, or maybe a function' : 'a string, a function, or an object'
757754
// Is function injection useful? Should we show it?
758755
- var hashes = lang == 'dart' ? 'They might be maps like this one:' : 'They tend to be object hashes like this one:'
759756
:marked

0 commit comments

Comments
 (0)