Open sibinxsimelabs opened 7 months ago
Encountering the same problem as well.
same problem and i solved with:
this.instance = this.dialogService.dialogComponentRefMap.get(ref)?.instance;
same problem and i solved with:
this.instance = this.dialogService.dialogComponentRefMap.get(ref)?.instance;
@salvatoremadonia Didn't solve it for me.
If what you want is the config object passed on the dialogService.open method, you can workaround by passing a DynamicDialogConfig in the constructor of the component you're opening.
Something like this:
@Component({
standalone: true,
imports: [DynamicDialogModule],
selector: 'app-dialog-test',
providers: [DialogService],
template: `<p>{{ config.data.message }}</p>`
})
export class DialogTestComponent {
constructor(private ref: DynamicDialogRef, public config: DynamicDialogConfig ) { }
}
Thanks! This solves the problem.
I got the same error, but my dialog shows it's content. My error is in the following method: https://github.com/primefaces/primeng/blob/master/src/app/components/dynamicdialog/dynamicdialog.ts#L329
loadChildComponent(componentType: Type<any>) {
let viewContainerRef = this.insertionPoint?.viewContainerRef;
viewContainerRef?.clear();
this.componentRef = viewContainerRef?.createComponent(componentType);
this.dialogRef.onChildComponentLoaded.next(this.componentRef!.instance);
}
this.componentRef is undefined.
In case this helps someone, I completely forgot to import my custom dialog component (standalone) in the component that was opening the dialog. Angular rendered the template but it was not functional and there was no error in the console 😅
Describe the bug
getInstance method product
Cannot read properties of undefined (reading 'instance') at DialogService.getInstance
error. So component not displaying . Same can be reproduce in PrimeNG dynamic dialog exampleEnvironment
Development
Reproducer
https://stackblitz.com/edit/nga6lg
Angular version
17.1.X
PrimeNG version
17.7.X
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
18.9.0
Browser(s)
Edge
Steps to reproduce the behavior
Expected behavior
It should not throw any error and show dynamic dialog component