I have read about ViewContainerRef, ComponentFactoryResolver.
Basically:
put tag in your html
declare the following in your ts: @ViewChild('parent', { read: ViewContainerRef }) parent: ViewContainerRef;
instantiate your component using: const childComponent = this.componentFactoryResolver.resolveComponentFactory(ChildComponent ); this.parent.createComponent(childComponent);
However, it does not work on already exist in your html on your page load.
The problem is I am using a popup that is generated using google map api (the popup where it appears when you click somewhere on the map).
I need to put div parent tag after the popup appears
var infowindow = new google.maps.InfoWindow({
// content: this.contentString
content: " <div #parent></div>"
});
Therefore I tried to bind it into onclick event on the popup as the following:
marker.addListener('click', () => {
infowindow.open(this.map, marker);
const childComponent = this.componentFactoryResolver.resolveComponentFactory(CentreDetailsComponent);
this.parent.createComponent(childComponent);
});
However, it does not work as per the screenshot. Is it because of the div parent tag is not generated on page load? can someone please assist? Thx