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

21 lines
589 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
`provide(MyService, {useClass: MyMockService})``provide`|`useClass`
Sets or overrides the provider for MyService to the MyMockService class.
@cheatsheetItem
`provide(MyService, {useFactory: myFactory})``provide`|`useFactory`
Sets or overrides the provider for MyService to the myFactory factory function.
@cheatsheetItem
`provide(MyValue, {useValue: 41})``provide`|`useValue`
Sets or overrides the provider for MyValue to the value 41.