簡體   English   中英

如何將自定義組件動態加載到div? 角度2

[英]How to load custom components dynamically to div? Angular2

ANGULAR2 ,我想將所有自定義組件加載到基於customComponentsList的html div中。

我的實際情況是我有考慮

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)) 

自定義組件。

我必須按照行和列位置在div中顯示

    A B C
    D E
    F G H

這可能有效

<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); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM