Skip to content

Commit 8dd35de

Browse files
committed
Fix PageRouterOutlet crash with beta 16+
1 parent 94cde33 commit 8dd35de

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/nativescript-angular/router/page-router-outlet.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {isBlank, isPresent} from '@angular/core/src/facade/lang';
33
import {StringMapWrapper} from '@angular/core/src/facade/collection';
44

55
import {Attribute, DynamicComponentLoader, ComponentRef, ViewContainerRef,
6-
ElementRef, ReflectiveInjector, provide, Type, Component} from '@angular/core';
6+
ElementRef, ReflectiveInjector, provide, Type, Component, Inject} from '@angular/core';
77

88
import * as routerHooks from '@angular/router/src/lifecycle/lifecycle_annotations';
99
import {hasLifecycleHook} from '@angular/router/src/lifecycle/route_lifecycle_reflector';
@@ -13,9 +13,12 @@ import {Router, RouterOutlet, RouteData, RouteParams, ComponentInstruction,
1313
import {LocationStrategy} from '@angular/common';
1414
import {topmost} from "ui/frame";
1515
import {Page, NavigatedData} from "ui/page";
16+
import {DEVICE} from "../platform-providers";
17+
import {Device} from "platform";
1618
import {log} from "./common";
1719
import {NSLocationStrategy} from "./ns-location-strategy";
1820
import {DetachedLoader} from "../common/detached-loader";
21+
import {ViewUtil} from "../view-util";
1922

2023
let _resolveToTrue = PromiseWrapper.resolve(true);
2124

@@ -66,13 +69,17 @@ export class PageRouterOutlet extends RouterOutlet {
6669

6770
private componentRef: ComponentRef = null;
6871
private currentInstruction: ComponentInstruction = null;
72+
private viewUtil: ViewUtil;
6973

7074
constructor(private containerRef: ViewContainerRef,
7175
private loader: DynamicComponentLoader,
7276
private parentRouter: Router,
7377
@Attribute('name') nameAttr: string,
74-
private location: NSLocationStrategy) {
78+
private location: NSLocationStrategy,
79+
@Inject(DEVICE) device: Device
80+
) {
7581
super(containerRef, loader, parentRouter, nameAttr);
82+
this.viewUtil = new ViewUtil(device);
7683
}
7784

7885
/**
@@ -154,9 +161,7 @@ export class PageRouterOutlet extends RouterOutlet {
154161
//Component loaded. Find its root native view.
155162
const componentView = componentRef.location.nativeElement;
156163
//Remove it from original native parent.
157-
if (<any>componentView.parent) {
158-
(<any>componentView.parent).removeChild(componentView);
159-
}
164+
this.viewUtil.removeChild(componentView.parent, componentView);
160165
//Add it to the new page
161166
page.content = componentView;
162167

0 commit comments

Comments
 (0)