1 | /**
|
2 | * @license
|
3 | * Copyright Google Inc. All Rights Reserved.
|
4 | *
|
5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | * found in the LICENSE file at https://angular.io/license
|
7 | */
|
8 | /**
|
9 | * Creates a token that can be used in a DI Provider.
|
10 | *
|
11 | * ### Example ([live demo](http://plnkr.co/edit/Ys9ezXpj2Mnoy3Uc8KBp?p=preview))
|
12 | *
|
13 | * ```typescript
|
14 | * var t = new OpaqueToken("value");
|
15 | *
|
16 | * var injector = Injector.resolveAndCreate([
|
17 | * {provide: t, useValue: "bindingValue"}
|
18 | * ]);
|
19 | *
|
20 | * expect(injector.get(t)).toEqual("bindingValue");
|
21 | * ```
|
22 | *
|
23 | * Using an `OpaqueToken` is preferable to using strings as tokens because of possible collisions
|
24 | * caused by multiple providers using the same string as two different tokens.
|
25 | *
|
26 | * Using an `OpaqueToken` is preferable to using an `Object` as tokens because it provides better
|
27 | * error messages.
|
28 | * @deprecated since v4.0.0 because it does not support type information, use `InjectionToken<?>`
|
29 | * instead.
|
30 | */
|
31 | export declare class OpaqueToken {
|
32 | protected _desc: string;
|
33 | constructor(_desc: string);
|
34 | toString(): string;
|
35 | }
|
36 | /**
|
37 | * Creates a token that can be used in a DI Provider.
|
38 | *
|
39 | * Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
|
40 | * runtime representation) such as when injecting an interface, callable type, array or
|
41 | * parametrized type.
|
42 | *
|
43 | * `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
|
44 | * the `Injector`. This provides additional level of type safety.
|
45 | *
|
46 | * ```
|
47 | * interface MyInterface {...}
|
48 | * var myInterface = injector.get(new InjectionToken<MyInterface>('SomeToken'));
|
49 | * // myInterface is inferred to be MyInterface.
|
50 | * ```
|
51 | *
|
52 | * ### Example
|
53 | *
|
54 | * {@example core/di/ts/injector_spec.ts region='InjectionToken'}
|
55 | *
|
56 | * @stable
|
57 | */
|
58 | export declare class InjectionToken<T> extends OpaqueToken {
|
59 | private _differentiate_from_OpaqueToken_structurally;
|
60 | constructor(desc: string);
|
61 | toString(): string;
|
62 | }
|
63 |
|
\ | No newline at end of file |