angular-cn/modules/angular2/docs/cheatsheet/dependency-injection.md

27 lines
655 B
Markdown
Raw Normal View History

2015-11-06 07:26:24 -05:00
@cheatsheetSection
Dependency injection configuration
@cheatsheetIndex 9
2015-11-06 07:26:24 -05:00
@description
`import {provide} from 'angular2/angular2';`
@cheatsheetItem
syntax:
`provide(MyService, {useClass: MyMockService})`|`provide`|`useClass`
description:
2015-11-06 07:26:24 -05:00
Sets or overrides the provider for MyService to the MyMockService class.
@cheatsheetItem
syntax:
`provide(MyService, {useFactory: myFactory})`|`provide`|`useFactory`
description:
2015-11-06 07:26:24 -05:00
Sets or overrides the provider for MyService to the myFactory factory function.
@cheatsheetItem
syntax:
`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.