@@ -2,8 +2,12 @@ import {PromiseWrapper} from '@angular/core/src/facade/async';
2
2
import { isBlank , isPresent } from '@angular/core/src/facade/lang' ;
3
3
import { StringMapWrapper } from '@angular/core/src/facade/collection' ;
4
4
5
- import { Attribute , DynamicComponentLoader , ComponentRef , ViewContainerRef ,
6
- ElementRef , ReflectiveInjector , provide , Type , Component } from '@angular/core' ;
5
+ import {
6
+ Attribute , DynamicComponentLoader , ComponentRef ,
7
+ ViewContainerRef , ViewChild , ElementRef ,
8
+ ReflectiveInjector , provide , Type ,
9
+ Component , Inject
10
+ } from '@angular/core' ;
7
11
8
12
import * as routerHooks from '@angular/router/src/lifecycle/lifecycle_annotations' ;
9
13
import { hasLifecycleHook } from '@angular/router/src/lifecycle/route_lifecycle_reflector' ;
@@ -13,9 +17,12 @@ import {Router, RouterOutlet, RouteData, RouteParams, ComponentInstruction,
13
17
import { LocationStrategy } from '@angular/common' ;
14
18
import { topmost } from "ui/frame" ;
15
19
import { Page , NavigatedData } from "ui/page" ;
20
+ import { DEVICE } from "../platform-providers" ;
21
+ import { Device } from "platform" ;
16
22
import { log } from "./common" ;
17
23
import { NSLocationStrategy } from "./ns-location-strategy" ;
18
24
import { DetachedLoader } from "../common/detached-loader" ;
25
+ import { ViewUtil } from "../view-util" ;
19
26
20
27
let _resolveToTrue = PromiseWrapper . resolve ( true ) ;
21
28
@@ -66,13 +73,19 @@ export class PageRouterOutlet extends RouterOutlet {
66
73
67
74
private componentRef : ComponentRef = null ;
68
75
private currentInstruction : ComponentInstruction = null ;
76
+ private viewUtil : ViewUtil ;
77
+ @ViewChild ( 'loader' , { read : ViewContainerRef } ) childContainerRef : ViewContainerRef ;
69
78
70
- constructor ( private containerRef : ViewContainerRef ,
79
+ constructor (
80
+ private containerRef : ViewContainerRef ,
71
81
private loader : DynamicComponentLoader ,
72
82
private parentRouter : Router ,
73
83
@Attribute ( 'name' ) nameAttr : string ,
74
- private location : NSLocationStrategy ) {
84
+ private location : NSLocationStrategy ,
85
+ @Inject ( DEVICE ) device : Device
86
+ ) {
75
87
super ( containerRef , loader , parentRouter , nameAttr ) ;
88
+ this . viewUtil = new ViewUtil ( device ) ;
76
89
}
77
90
78
91
/**
@@ -128,7 +141,7 @@ export class PageRouterOutlet extends RouterOutlet {
128
141
129
142
const page = new Page ( ) ;
130
143
providersArray . push ( provide ( Page , { useValue : page } ) ) ;
131
- resultPromise = this . loader . loadNextToLocation ( DetachedLoader , this . containerRef , ReflectiveInjector . resolve ( providersArray ) )
144
+ resultPromise = this . loader . loadNextToLocation ( DetachedLoader , this . childContainerRef , ReflectiveInjector . resolve ( providersArray ) )
132
145
. then ( ( pageComponentRef ) => {
133
146
loaderRef = pageComponentRef ;
134
147
return ( < DetachedLoader > loaderRef . instance ) . loadComponent ( componentType ) ;
@@ -154,9 +167,7 @@ export class PageRouterOutlet extends RouterOutlet {
154
167
//Component loaded. Find its root native view.
155
168
const componentView = componentRef . location . nativeElement ;
156
169
//Remove it from original native parent.
157
- if ( < any > componentView . parent ) {
158
- ( < any > componentView . parent ) . removeChild ( componentView ) ;
159
- }
170
+ this . viewUtil . removeChild ( componentView . parent , componentView ) ;
160
171
//Add it to the new page
161
172
page . content = componentView ;
162
173
0 commit comments