I am new to Angular 6
I just want to ask my question regarding Angular Dynamic Component Creation.
I have created dynamic component and added it to the View Container see my code snippet.
//dynamic Component Creation
private taskCompList=[];
var componentFactory=this.componentResolver.resolveComponentFactory(TaskInputComponent);
let taskInputComp=this.taskListView.createComponent(componentFactory);
let taskCompInstance=taskInputComp.instance;
taskCompInstance.selfRef=taskInputComp;
//adding created component to array
this.taskCompList.push(taskCompInstance);
In above code I have captured the dynamically created component in taskCompList array.
Later, I have the iterated the taskCompArray to get bean from created child Component
//itreating array to get component values
private taskModel=[];
this.taskCompList.forEach(taskInputComp=>
{
//getting childcomponent bean
this.taskModel.push(taskInputComp.getTaskBean());
console.info(taskInputComp.getTaskBean().taskName);
});
This one perfectly works.
But my question is instead of capturing the child component in array and iterating it. Is there is any other possible solution to handle the created child components.
More specifically using any decorators like @ViewChild, @ViewChildren to get child component values (Child component bean in my scenario).