0

ANGULAR2, I want to load all my custom component into a html div based on customComponentsList.

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

    A B C
    D E
    F G H
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

0

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); 
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567