1
1
import {
2
2
Attribute , ComponentFactory , ComponentRef , Directive ,
3
- ReflectiveInjector , ResolvedReflectiveProvider , ViewContainerRef ,
3
+ ViewContainerRef ,
4
4
Inject , ComponentFactoryResolver , Injector
5
5
} from "@angular/core" ;
6
6
import { isPresent } from "../lang-facade" ;
@@ -68,7 +68,9 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
68
68
69
69
public outletMap : RouterOutletMap ;
70
70
71
- get locationInjector ( ) : Injector { return this . containerRef . injector ; }
71
+ /** @deprecated from Angular since v4 */
72
+ get locationInjector ( ) : Injector { return this . location . injector ; }
73
+ /** @deprecated from Angular since v4 */
72
74
get locationFactoryResolver ( ) : ComponentFactoryResolver { return this . resolver ; }
73
75
74
76
get isActivated ( ) : boolean {
@@ -92,7 +94,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
92
94
93
95
constructor (
94
96
parentOutletMap : RouterOutletMap ,
95
- private containerRef : ViewContainerRef ,
97
+ private location : ViewContainerRef ,
96
98
@Attribute ( "name" ) name : string ,
97
99
private locationStrategy : NSLocationStrategy ,
98
100
private componentFactoryResolver : ComponentFactoryResolver ,
@@ -145,37 +147,35 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
145
147
* Called by the Router to instantiate a new component during the commit phase of a navigation.
146
148
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
147
149
*/
148
- activate (
149
- activatedRoute : ActivatedRoute , resolver : ComponentFactoryResolver , injector : Injector ,
150
- providers : ResolvedReflectiveProvider [ ] , outletMap : RouterOutletMap ) : void {
150
+ activateWith (
151
+ activatedRoute : ActivatedRoute , resolver : ComponentFactoryResolver | null ,
152
+ outletMap : RouterOutletMap ) : void {
151
153
this . outletMap = outletMap ;
152
154
this . currentActivatedRoute = activatedRoute ;
153
155
156
+ resolver = resolver || this . resolver ;
157
+
154
158
if ( this . locationStrategy . _isPageNavigatingBack ( ) ) {
155
159
this . activateOnGoBack ( activatedRoute , outletMap ) ;
156
160
} else {
157
- this . activateOnGoForward ( activatedRoute , providers , outletMap , resolver , injector ) ;
161
+ this . activateOnGoForward ( activatedRoute , outletMap , resolver ) ;
158
162
}
159
163
}
160
164
161
165
private activateOnGoForward (
162
166
activatedRoute : ActivatedRoute ,
163
- providers : ResolvedReflectiveProvider [ ] ,
164
167
outletMap : RouterOutletMap ,
165
- loadedResolver : ComponentFactoryResolver ,
166
- injector : Injector ) : void {
168
+ loadedResolver : ComponentFactoryResolver ) : void {
167
169
const factory = this . getComponentFactory ( activatedRoute , loadedResolver ) ;
168
170
169
171
const pageRoute = new PageRoute ( activatedRoute ) ;
170
- providers = [ ...providers , ...ReflectiveInjector . resolve (
171
- [ { provide : PageRoute , useValue : pageRoute } ] ) ] ;
172
+ const inj = new OutletInjector ( activatedRoute , outletMap , this . location . injector ) ;
172
173
173
174
if ( this . isInitialPage ) {
174
175
log ( "PageRouterOutlet.activate() initial page - just load component" ) ;
175
176
this . isInitialPage = false ;
176
- const inj = ReflectiveInjector . fromResolvedProviders ( providers , injector ) ;
177
- this . currentActivatedComp = this . containerRef . createComponent (
178
- factory , this . containerRef . length , inj , [ ] ) ;
177
+ this . currentActivatedComp = this . location . createComponent (
178
+ factory , this . location . length , inj , [ ] ) ;
179
179
180
180
this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
181
181
@@ -189,13 +189,8 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
189
189
isNavigation : true ,
190
190
componentType : factory . componentType
191
191
} ) ;
192
- const pageResolvedProvider = ReflectiveInjector . resolve ( [
193
- { provide : Page , useValue : page }
194
- ] ) ;
195
- const childInjector = ReflectiveInjector . fromResolvedProviders (
196
- [ ...providers , ...pageResolvedProvider ] , injector ) ;
197
- const loaderRef = this . containerRef . createComponent (
198
- this . detachedLoaderFactory , this . containerRef . length , childInjector , [ ] ) ;
192
+ const loaderRef = this . location . createComponent (
193
+ this . detachedLoaderFactory , this . location . length , inj , [ ] ) ;
199
194
loaderRef . changeDetectorRef . detectChanges ( ) ;
200
195
201
196
this . currentActivatedComp = loaderRef . instance . loadWithFactory ( factory ) ;
@@ -275,6 +270,23 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
275
270
}
276
271
}
277
272
273
+ class OutletInjector implements Injector {
274
+ constructor (
275
+ private route : ActivatedRoute , private map : RouterOutletMap , private parent : Injector ) { }
276
+
277
+ get ( token : any , notFoundValue ?: any ) : any {
278
+ if ( token === ActivatedRoute ) {
279
+ return this . route ;
280
+ }
281
+
282
+ if ( token === RouterOutletMap ) {
283
+ return this . map ;
284
+ }
285
+
286
+ return this . parent . get ( token , notFoundValue ) ;
287
+ }
288
+ }
289
+
278
290
function log ( msg : string ) {
279
291
routerLog ( msg ) ;
280
292
}
0 commit comments