Avi
Avi

Reputation: 1964

Output parameter in dynamic components

When we want the Parent component listens for child event we use the @output parameter and subscribing on the parent markup:

<my-tag (onMyEvent)="onMyEvent($event)"></my-tag>

how do I do it with ComponentResolver?

Upvotes: 5

Views: 4925

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657416

That's not supported.
- use a shared service with components that are dynamically added using ViewContainerRef.createComponent() or
- use the componentRef it returns to wire inputs and outputs imperatively.

this.resolver.resolveComponent(this.type).then((factory:ComponentFactory<any>) => {
  this.cmpRef = this.target.createComponent(factory);
  this.cmpRef.instance.someOutput.subscribe(...)
  this.cmpRef.instance.someInput = this.someInputValue;
});

Upvotes: 12

Related Questions