I am getting this error
Parent HTML pseudo code:
<ul>
@for (option of options, track option.title) {
<li>
<row>
<column>
<button (clicked)="onButtonClicked(option)"
<column>
</row>
</li>
}
</ul
<ng-container #dynamicComponentContainer></ng-container>
Parent TS pseudo code:
@ViewChild('dynamicComponentContainer', {read: ViewContainerRef})
protected dynamicComponentContainer!: ViewContainerRef;
protected child1Ref?: ComponentRef<Child1Component>;
protected onButtonClicked(option) {
if (option.title === 'Component1') {
this.dynamicComponentContainer.clear();
this.child1Ref.setInput('isOpen', true);
this.child1Ref.instance.closed.subscribe(() => {
if (!this.compnent1Ref) {
return;
}
this.component1Ref.destroy();
});
}
}
Child1 HTML:
<custom-dialog
[openValue]="isOpen()"
(closed)="closeDialog()">
</custom-dialog>
Child1 TS:
isOpen = input.required<boolean>();
closed = output<void>();
protected closeDialog() {
this.closed.emit();
}
But whenever I closed the dialog, I get NG0953: Unexpected emit for destroyed OutputRef. The owning directive/component is destroyed
How can I fix this? I see there's an OutputRef that automatically cleans up the subscription if the component of the output is destroyed. Should I unsubscribe from the this.child1Ref.instance.closed (after saving to a variable) before destroying?