export class HotspotWrapperComponent implements OnInit, OnChanges { @ViewChild('container', { read: ViewContainerRef }) container!: ViewContainerRef; @Input() message: string = ''; @Input() count: number = 0; private componentRef: any; constructor(private cfr: ComponentFactoryResolver) {} async ngOnInit() { await this.loadHotspotComponent(); } ngOnChanges(changes: SimpleChanges) { if (this.componentRef) { if (changes.message) { this.componentRef.instance.message = this.message; } if (changes.count) { this.componentRef.instance.count = this.count; } this.componentRef.changeDetectorRef.detectChanges(); } } private async loadHotspotComponent() { try { // Clear previous component if exists this.container.clear(); // Load the remote component const { HotspotComponent } = await import('hostApp/HotspotComponent'); // Create component const factory = this.cfr.resolveComponentFactory(HotspotComponent); this.componentRef = this.container.createComponent(factory); // Set initial inputs this.componentRef.instance.message = this.message; this.componentRef.instance.count = this.count; } catch (error) { console.error('Error loading HotspotComponent:', error); } } ngOnDestroy() { if (this.componentRef) { this.componentRef.destroy(); } } } Continue reading...