Skip to content

Commit 558fc80

Browse files
fix(ng2.UIView): Make routed to component appear *inside* UIView, not next to it.
1 parent 822fc10 commit 558fc80

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ng2/directives/uiView.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @module ng2_directives */ /** */
22
import {
33
Component, ComponentResolver, ComponentFactory,
4-
ViewContainerRef, ReflectiveInjector, InputMetadata, ComponentMetadata
4+
ViewContainerRef, ReflectiveInjector, InputMetadata, ComponentMetadata, ViewChild
55
} from '@angular/core';
66
import {provide} from "@angular/core";
77
import {Input} from "@angular/core";
@@ -103,7 +103,7 @@ const ng2ComponentInputs = (ng2CompClass) => {
103103
*/
104104
@Component({
105105
selector: 'ui-view, [ui-view]',
106-
template: ''
106+
template: `<template #componentTarget></template>`
107107
// styles: [`
108108
// .done-true {
109109
// text-decoration: line-through;
@@ -122,6 +122,7 @@ const ng2ComponentInputs = (ng2CompClass) => {
122122
// </div>`
123123
})
124124
export class UIView {
125+
@ViewChild('componentTarget', {read: ViewContainerRef}) componentTarget;
125126
@Input('name') name: string;
126127
@Input('ui-view') set _name(val) { this.name = val; }
127128
componentRef: ComponentRef<any>;
@@ -192,7 +193,7 @@ export class UIView {
192193
let createComponent = (factory: ComponentFactory<any>) => {
193194
let parentInjector = this.viewContainerRef.injector;
194195
let childInjector = ReflectiveInjector.resolveAndCreate(rawProviders, parentInjector);
195-
let ref = this.componentRef = this.viewContainerRef.createComponent(factory, undefined, childInjector);
196+
let ref = this.componentRef = this.componentTarget.createComponent(factory, undefined, childInjector);
196197

197198
// TODO: wire uiCanExit and uiOnParamsChanged callbacks
198199

0 commit comments

Comments
 (0)