File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed
modules/angular2/src/core/di Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change 11import { CONST } from 'angular2/src/core/facade/lang' ;
22
33/**
4- * By binding to an `OpaqueToken` you can enable an application to return more meaningful error
5- * messages.
4+ * Creates a token that can be used in a DI Binding.
65 *
7- * ## Example
6+ * ### Example ([live demo](http://plnkr.co/edit/Ys9ezXpj2Mnoy3Uc8KBp?p=preview))
87 *
8+ * ```typescript
9+ * var t = new OpaqueToken("binding");
10+ *
11+ * var injector = Injector.resolveAndCreate([
12+ * bind(t).toValue("bindingValue")
13+ * ]);
14+ *
15+ * expect(injector.get(t)).toEqual("bindingValue");
916 * ```
10- * // While the following would work, see below for the preferred way
11- * var binding = bind('value0').toValue(0);
12- * ...
13- * var value = injector.get('value0');
1417 *
15- * // An OpaqueToken is the preferred way and lead to more helpful error messages
16- * export value0Token = new OpaqueToken('value0');
17- * var binding = bind(value0Token).toValue(0);
18- * ...
19- * var value = injector.get(value0Token);
18+ * Using an ` OpaqueToken` is preferable to using strings as tokens because of possible collisions
19+ * caused by multiple bindings using the same string as two different tokens.
20+ *
21+ * Using an `OpaqueToken` is preferable to using an `Object` as tokens because it provides better
22+ * error messages.
2023 * ```
2124 */
2225@CONST ( )
You can’t perform that action at this time.
0 commit comments