How do I pass input and event output to dynamic component in ng-container using ngComponentOutlet?

569 Views Asked by At

I'm trying to pass an event emitter and input to a dynamic component, but not able to get it through. My angular version is 10.

I want to perform something like this:

<ng-container [ngComponentOutlet]="addressForm" [isBilling]="isBilling" (saveAddressEvent)="saveNewAddress($event)"></ng-container>

Tried passing the inputs and outputs as usual but it's not working.

1

There are 1 best solutions below

0
On

There is another directive called ngComponentInputs, you just need to set an object in this directive to pass all the @Inputs that you component receives

<ng-container 
   [ngComponentOutlet]="addressForm" 
   [ngComponentInputs]="{isBilling: isBilling}"
    ></ng-container>

But I think there is no way to listen the events from this dynamic components. I have the same problem, quite useless this ngComponentOutlet directive in this scenario. I don't know what is the point of load component dynamically if we can't listen their events from the outside