In my angular 6 project, I have a dynamically created component like below:
@Component({
selector: 'app-staff-dash',
template: `
<template #tasksContainer></template>
`
})
export class StaffDashComponent implements OnInit {
componentRef: any;
factory: any;
@ViewChild('tasksContainer', { read: ViewContainerRef }) tasksEntry: ViewContainerRef;
constructor(
@Inject(ComponentFactoryResolver) private resolver: ComponentFactoryResolver
) {
}
ngOnInit() {
this.createTasksComponent();
}
createTasksComponent(): void {
this.tasksEntry.clear();
this.factory = this.resolver.resolveComponentFactory(TasksComponent);
this.componentRef = this.tasksEntry.createComponent(this.factory);
}
}
StaffDashComponent is the parent and TasksComponent is the child. Now I want some data to be passed from TasksComponent to StaffDashComponent using @Output. How can I achieve that?