2016-10-20 54 views
0

ANGULAR2, 我想将所有我的自定义组件加载到基于customComponentsList的html div中。如何将自定义组件动态加载到div? Angular2

我的实际情况是considor我有

A(0-row,0-column),B(0,1),C(0,2),D(1,0),E(1,1),F(2,0), G(2,1), H(2-row,2-column)) 

自定义组件。

我有一个像

A B C 
    D E 
    F G H 
+0

听起来像http://stackoverflow.com/questions/ 36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468 –

+0

这与Angular 2有什么关系?听起来很像纯粹的CSS问题。 –

+0

谢谢@GünterZöchbauer,真的很有帮助,我有一个疑问,我怎么能加载组件行,列positioin在dom –

回答

0

按行和列位置在div来显示这可能会实现

<div #target x="0" y="0"></div> 
<div #target x="1" y="0"></div> 
<div #target x="2" y="0"></div> 

<div #target x="0" y="1"></div> 
<div #target x="1" y="1"></div> 
<div #target x="2" y="1"></div> 

<div #target x="0" y="2"></div> 
<div #target x="1" y="2"></div> 
<div #target x="2" y="2"></div> 
@ViewChildren('target', {read: ViewContainerRef}) targets: QueryList<ViewContainerRef>; 

// this.targets is not filled before `ngAfterViewInit()` was called 
addComponent(x, y) { 
    let t = this.targets(y * 3 + x); 
} 
+0

我使用你的答案'http://stackoverflow.com/questions/37656742/how-to-use-ngfor-to-display-the-data-as-matrix'。 –

+0