1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

module fedration unable to get parent host componet to child

Discussão em 'Angular' iniciado por Kranthi Yellu, Junho 11, 2025.

  1. 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...

Compartilhe esta Página