[英]How to load custom components dynamically to div? Angular2
ANGULAR2 , I want to load all my custom component into a html div based on customComponentsList. ANGULAR2 ,我想将所有自定义组件加载到基于customComponentsList的html div中。
My actual scenario is considor i have 我的实际情况是我有考虑
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))
custom components. 自定义组件。
I have to display in div as per row and column positions like 我必须按照行和列位置在div中显示
A B C
D E
F G H
This might work 这可能有效
<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.