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

34 lines
1.0 KiB
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
{@target ts}`import {provide} from 'angular2/core';`{@endtarget}
{@target js}Available from the `ng.core` namespace{@endtarget}
{@target dart}`import 'package:angular2/core.dart';`{@endtarget}
2015-11-06 07:26:24 -05:00
@cheatsheetItem
syntax(ts dart):
`{ provide: MyService, useClass: MyMockService }`|`provide`|`useClass`
syntax(js):
`{ 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(ts dart):
`{ provide: MyService, useFactory: myFactory }`|`provide`|`useFactory`
syntax(js):
`{ 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(ts dart):
`{ provide: MyValue, useValue: 41 }`|`provide`|`useValue`
syntax(js):
`{ 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.