This repository was archived by the owner on Dec 4, 2017. It is now read-only.
File tree 3 files changed +6
-7
lines changed
_examples/upgrade-module/ts/app/1-to-2-providers
3 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { HeroesService } from './heroes.service';
14
14
UpgradeModule
15
15
] ,
16
16
providers : [ {
17
- provide : 'heroes' ,
17
+ provide : HeroesService ,
18
18
useFactory : ( i : any ) => i . get ( 'heroes' ) ,
19
19
deps : [ '$injector' ]
20
20
} ] ,
Original file line number Diff line number Diff line change 1
1
// #docregion
2
- import { Component , Inject } from '@angular/core' ;
2
+ import { Component } from '@angular/core' ;
3
3
import { HeroesService } from './heroes.service' ;
4
4
import { Hero } from '../hero' ;
5
5
@@ -11,7 +11,7 @@ import { Hero } from '../hero';
11
11
} )
12
12
export class HeroDetailComponent {
13
13
hero : Hero ;
14
- constructor ( @ Inject ( 'heroes' ) heroes : HeroesService ) {
14
+ constructor ( heroes : HeroesService ) {
15
15
this . hero = heroes . get ( ) [ 0 ] ;
16
16
}
17
17
}
Original file line number Diff line number Diff line change @@ -269,8 +269,7 @@ table
269
269
* We can make Angular 1 services available for injection to Angular 2 code
270
270
by *upgrading* them. The same singleton instance of each service is shared
271
271
between the frameworks. In Angular 2 these services will always be in the
272
- *root injector* and available to all components. They will always have
273
- *string tokens* - the same tokens that they have in Angular 1.
272
+ *root injector* and available to all components.
274
273
* We can also make Angular 2 services available for injection to Angular 1 code
275
274
by *downgrading* them. Only services from the Angular 2 root injector can
276
275
be downgraded. Again, the same singleton instances are shared between the frameworks.
@@ -731,12 +730,12 @@ figure
731
730
732
731
:marked
733
732
We can upgrade the service using a Angular 2 [Factory provider](./dependency-injection.html#factory-providers)
734
- that requests the service from the Angular 1 `$injector`. The name of the Angular 2 dependency is up to you :
733
+ that requests the service from the Angular 1 `$injector`:
735
734
736
735
+ makeExample('upgrade-module/ts/app/1-to-2-providers/app.module.ts' , 'register' , 'app.module.ts' )
737
736
738
737
:marked
739
- We can then inject it in Angular 2 using a string token :
738
+ We can then inject it in Angular 2 using it's class as a type annotation :
740
739
741
740
+ makeExample('upgrade-module/ts/app/1-to-2-providers/hero-detail.component.ts' , null , 'hero-detail.component.ts' )
742
741
You can’t perform that action at this time.
0 commit comments