ngOnChanges not working for angular CDK component portal instance

Viewed 226

I am using angular cdk ovelay to open dialog.

Here is the code

openDialog(component: any, dialogConfig: DialogConfig): any {
    const config = new OverlayConfig();
    config.height = dialogConfig.height;
    config.width = dialogConfig.width;
    config.positionStrategy = this.overlay.position().global().centerHorizontally().centerVertically();
    config.hasBackdrop = true;
    config.backdropClass = dialogConfig.backdropClass;

    const componentOverlayRef = this.overlay.create(config);
    const componentPortal = new ComponentPortal(component);
    const componentRef = componentOverlayRef.attach(componentPortal);

    componentOverlayRef.backdropClick().subscribe(() => {
        componentOverlayRef.dispose();
    });
    return componentRef;
}

And here is how I am using it

const _dialogConfig = new DialogConfig({
        backdropClass: "dialog-backdrop"
    });

const _componentRef: any = this.openDialog(MyComponent, _dialogConfig);
const _componentInstanceRef: MyComponent= _componentRef.instance;
_componentInstanceRef.id= 10;
_componentRef.changeDetectorRef.detectChanges();

In my component, id is the @Input and i am using ngOnChanges to listen change in id.

But ngOnChanges not getting called even after I have used

_componentRef.changeDetectorRef.detectChanges();

what is the issue? Or any other way to to do it?

0 Answers
Related