DEV Community

Discussion on: Manually Lazy load Components in Angular 8

Collapse
 
fuhrermani profile image
fuhrermani

how to pass inputs and catch outputs from this component.

Collapse
 
binarysort profile image
Mayank Dubey • Edited

The createComponent() method returns a reference to the loaded component. Use that reference to interact with the component by assigning to its properties or calling its methods.

Add input and output in component:-

@Input()
data: string;

@Output()
event = new EventEmitter();

In the service just add:-

const compRef = container.createComponent(compFactory);

(compRef.instance as LazyComponent).data = 'this is data';
(compRef.instance as LazyComponent).event.subscribe(v => ... );

Read more about dynamic components here: angular.io/guide/dynamic-component...

Some comments have been hidden by the post's author - find out more