@@ -3,18 +3,19 @@ import {
3
3
ViewContainerRef ,
4
4
Inject , ComponentFactoryResolver , Injector
5
5
} from "@angular/core" ;
6
- import { isPresent } from "../lang-facade" ;
7
6
import { RouterOutletMap , ActivatedRoute , PRIMARY_OUTLET } from "@angular/router" ;
8
- import { NSLocationStrategy } from "./ns-location-strategy" ;
9
- import { DEVICE , PAGE_FACTORY , PageFactory } from "../platform-providers" ;
10
7
import { Device } from "tns-core-modules/platform" ;
11
- import { routerLog } from "../trace" ;
12
- import { DetachedLoader } from "../common/detached-loader" ;
13
- import { ViewUtil } from "../view-util" ;
14
8
import { Frame } from "tns-core-modules/ui/frame" ;
15
9
import { Page , NavigatedData } from "tns-core-modules/ui/page" ;
16
10
import { BehaviorSubject } from "rxjs/BehaviorSubject" ;
17
11
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
+
18
19
interface CacheItem {
19
20
componentRef : ComponentRef < any > ;
20
21
reusedRoute : PageRoute ;
@@ -169,13 +170,15 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
169
170
const factory = this . getComponentFactory ( activatedRoute , loadedResolver ) ;
170
171
171
172
const pageRoute = new PageRoute ( activatedRoute ) ;
172
- const inj = new OutletInjector ( activatedRoute , outletMap , this . location . injector ) ;
173
173
174
174
if ( this . isInitialPage ) {
175
175
log ( "PageRouterOutlet.activate() initial page - just load component" ) ;
176
+
176
177
this . isInitialPage = false ;
178
+
179
+ const injector = new OutletInjector ( activatedRoute , outletMap , this . location . injector ) ;
177
180
this . currentActivatedComp = this . location . createComponent (
178
- factory , this . location . length , inj , [ ] ) ;
181
+ factory , this . location . length , injector , [ ] ) ;
179
182
180
183
this . currentActivatedComp . changeDetectorRef . detectChanges ( ) ;
181
184
@@ -189,8 +192,11 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
189
192
isNavigation : true ,
190
193
componentType : factory . componentType
191
194
} ) ;
195
+
196
+ const childInjector = new ChildInjector ( activatedRoute , outletMap , page , this . location . injector ) ;
197
+
192
198
const loaderRef = this . location . createComponent (
193
- this . detachedLoaderFactory , this . location . length , inj , [ ] ) ;
199
+ this . detachedLoaderFactory , this . location . length , childInjector , [ ] ) ;
194
200
loaderRef . changeDetectorRef . detectChanges ( ) ;
195
201
196
202
this . currentActivatedComp = loaderRef . instance . loadWithFactory ( factory ) ;
@@ -287,6 +293,21 @@ class OutletInjector implements Injector {
287
293
}
288
294
}
289
295
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
+
290
311
function log ( msg : string ) {
291
312
routerLog ( msg ) ;
292
313
}
0 commit comments