@@ -3,18 +3,19 @@ import {
33 ViewContainerRef ,
44 Inject , ComponentFactoryResolver , Injector
55} from "@angular/core" ;
6- import { isPresent } from "../lang-facade" ;
76import { RouterOutletMap , ActivatedRoute , PRIMARY_OUTLET } from "@angular/router" ;
8- import { NSLocationStrategy } from "./ns-location-strategy" ;
9- import { DEVICE , PAGE_FACTORY , PageFactory } from "../platform-providers" ;
107import { Device } from "tns-core-modules/platform" ;
11- import { routerLog } from "../trace" ;
12- import { DetachedLoader } from "../common/detached-loader" ;
13- import { ViewUtil } from "../view-util" ;
148import { Frame } from "tns-core-modules/ui/frame" ;
159import { Page , NavigatedData } from "tns-core-modules/ui/page" ;
1610import { BehaviorSubject } from "rxjs/BehaviorSubject" ;
1711
12+ import { isPresent } from "../lang-facade" ;
13+ import { DEVICE , PAGE_FACTORY , PageFactory } from "../platform-providers" ;
14+ import { routerLog } from "../trace" ;
15+ import { DetachedLoader } from "../common/detached-loader" ;
16+ import { ViewUtil } from "../view-util" ;
17+ import { NSLocationStrategy } from "./ns-location-strategy" ;
18+
1819interface CacheItem {
1920 componentRef : ComponentRef < any > ;
2021 reusedRoute : PageRoute ;
@@ -169,13 +170,15 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
169170 const factory = this . getComponentFactory ( activatedRoute , loadedResolver ) ;
170171
171172 const pageRoute = new PageRoute ( activatedRoute ) ;
172- const inj = new OutletInjector ( activatedRoute , outletMap , this . location . injector ) ;
173173
174174 if ( this . isInitialPage ) {
175175 log ( "PageRouterOutlet.activate() initial page - just load component" ) ;
176+
176177 this . isInitialPage = false ;
178+
179+ const injector = new OutletInjector ( activatedRoute , outletMap , this . location . injector ) ;
177180 this . currentActivatedComp = this . location . createComponent (
178- factory , this . location . length , inj , [ ] ) ;
181+ factory , this . location . length , injector , [ ] ) ;
179182
180183 this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
181184
@@ -189,8 +192,11 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
189192 isNavigation : true ,
190193 componentType : factory . componentType
191194 } ) ;
195+
196+ const childInjector = new ChildInjector ( activatedRoute , outletMap , page , this . location . injector ) ;
197+
192198 const loaderRef = this . location . createComponent (
193- this . detachedLoaderFactory , this . location . length , inj , [ ] ) ;
199+ this . detachedLoaderFactory , this . location . length , childInjector , [ ] ) ;
194200 loaderRef . changeDetectorRef . detectChanges ( ) ;
195201
196202 this . currentActivatedComp = loaderRef . instance . loadWithFactory ( factory ) ;
@@ -287,6 +293,21 @@ class OutletInjector implements Injector {
287293 }
288294}
289295
296+ class ChildInjector extends OutletInjector {
297+ constructor (
298+ route : ActivatedRoute , map : RouterOutletMap , private page : Page , parent : Injector ) {
299+ super ( route , map , parent ) ;
300+ }
301+
302+ get ( token : any , notFoundValue ?: any ) : any {
303+ if ( token === Page ) {
304+ return this . page ;
305+ }
306+
307+ return super . get ( token , notFoundValue ) ;
308+ }
309+ }
310+
290311function log ( msg : string ) {
291312 routerLog ( msg ) ;
292313}
0 commit comments