2015-11-06 07:26:24 -05:00
|
|
|
@cheatsheetSection
|
|
|
|
Dependency injection configuration
|
2015-11-13 02:14:12 -05:00
|
|
|
@cheatsheetIndex 9
|
2015-11-06 07:26:24 -05:00
|
|
|
@description
|
2015-12-12 22:17:26 -05:00
|
|
|
{@target ts}`import {provide} from 'angular2/core';`{@endtarget}
|
|
|
|
{@target js}Available from the `ng.core` namespace{@endtarget}
|
2015-12-11 18:01:37 -05:00
|
|
|
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
|
2015-11-06 07:26:24 -05:00
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-12 22:17:26 -05:00
|
|
|
syntax(ts dart):
|
2015-12-09 07:33:42 -05:00
|
|
|
`provide(MyService, {useClass: MyMockService})`|`provide`|`useClass`
|
2015-12-12 22:17:26 -05:00
|
|
|
syntax(js):
|
|
|
|
`ng.core.provide(MyService, {useClass: MyMockService})`|`provide`|`useClass`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-11-06 07:26:24 -05:00
|
|
|
Sets or overrides the provider for MyService to the MyMockService class.
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-12 22:17:26 -05:00
|
|
|
syntax(ts dart):
|
2015-12-09 07:33:42 -05:00
|
|
|
`provide(MyService, {useFactory: myFactory})`|`provide`|`useFactory`
|
2015-12-12 22:17:26 -05:00
|
|
|
syntax(js):
|
|
|
|
`ng.core.provide(MyService, {useFactory: myFactory})`|`provide`|`useFactory`
|
2015-12-09 07:33:42 -05:00
|
|
|
description:
|
2015-11-06 07:26:24 -05:00
|
|
|
Sets or overrides the provider for MyService to the myFactory factory function.
|
|
|
|
|
|
|
|
|
|
|
|
@cheatsheetItem
|
2015-12-12 22:17:26 -05:00
|
|
|
syntax(ts dart):
|
|
|
|
`provide(MyValue, {useValue: 41})`|`provide`|`useValue`
|
|
|
|
syntax(js):
|
2015-12-09 07:33:42 -05:00
|
|
|
`provide(MyValue, {useValue: 41})`|`provide`|`useValue`
|
|
|
|
description:
|
2015-11-06 07:26:24 -05:00
|
|
|
Sets or overrides the provider for MyValue to the value 41.
|