I am faced with a challenge where I need to dynamically render a component using the following code snippet:
const component = this.resolver.resolveComponentFactory<BaseComponent(CommonPopupComponent).create(this.injector);
component.instance.data = data;
return component.location.nativeElement;
The issue is that I cannot utilize lifecycle hooks within myComponent due to its extension of another class.
@Component({
selector: 'app-common-popup',
templateUrl: './common-popup.component.html',
styleUrls: ['./common-popup.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush })
export class CommonPopupComponent extends BasePopupComponent implements OnInit { ... }
However, I have a requirement to execute a function when CommonPopupComponent is initialized (specifically in ngOnInit). Is there a way to call a function belonging to CommonPopupComponent from outside when it is being initialized?
Currently, I am calling my function within the constructor of CommonPopupComponent, but I feel there might be a more efficient approach available.