export class ProviderBuilder
export class ProviderBuilder
exported from angular2/core defined in angular2/src/core/di/provider.ts (line 388)
Helper class for the bind
function.
Constructor
constructor(token: any)
constructor(token: any)
Not Yet Documented
Members
token
token
Not Yet Documented
toClass(type: Type) : Provider
toClass(type: Type) : Provider
Binds a DI token to a class.
(live demo)
Because toAlias
and toClass
are often confused, the example contains
both use cases for easy comparison.
toValue(value: any) : Provider
toValue(value: any) : Provider
Binds a DI token to a value.
(live demo)
toAlias(aliasToken: /*Type*/ any) : Provider
toAlias(aliasToken: /*Type*/ any) : Provider
Binds a DI token to an existing token.
Angular will return the same instance as if the provided token was used. (This is
in contrast to useClass
where a separate instance of useClass
will be returned.)
(live demo)
Because toAlias
and toClass
are often confused, the example contains
both use cases for easy comparison.
toFactory(factory: Function, dependencies?: any[]) : Provider
toFactory(factory: Function, dependencies?: any[]) : Provider
Binds a DI token to a function which computes the value.
(live demo)
var injector = Injector.resolveAndCreate([
provide(Number, {useFactory: () => { return 1+2; }}),
provide(String, {useFactory: (v) => { return "Value: " + v; }, deps: [Number]})
]);
expect(injector.get(Number)).toEqual(3);
expect(injector.get(String)).toEqual('Value: 3');