Answer the question
In order to leave comments, you need to log in
How to nest components dynamically?
I have the following object:
let obj = {id: 1, children: [{id: 4, children: [{id: 5}, id: 1]}]}
<ng-container *ngFor="let element of obj?.children">
<div *ngIf="element.type == 'block">
<app-adresat-list *ngIf="element.id == 3" [parentBlock]="parentBlock" [list]="element?.children"></app-adresat-list>
... еще несколько других компонентов тут по условию
</div>
<div *ngIf="element.type = 'field'">
<app-field [field]="element"></app-field> <!-- Отрисовывает элемент формы по типу (input, select и тд)
</div>
</ng-container>
<app-root [children]="element">
to check if the element has children and draw them. Answer the question
In order to leave comments, you need to log in
At one time I met with this task on one project, the solution resulted in the library https://github.com/zircon63/ng-torque .
Used viewref create component
https://www.github.com/zircon63/ng-torque/tree/mas...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question