Cannot close stacked dynamic dialog from DynamicDialogRef.close() and escape key closes all dynamic dialogs
I'm submitting a ...
[X] bug report => Search github for a similar issue or PR before submitting
Plunkr Case (Bug Reports) Demo: https://github-fxeygh.stackblitz.io/ Editor: https://stackblitz.com/edit/github-fxeygh
Current behavior If you open inner dynamic dialogs via DialogService, firstly opened dialog cannot be closed programmatically calling by reference.close() method.
Expected behavior All stacking dialogs should be programmatically closable
Minimal reproduction of the problem with instructions Steps to reproduce the problem are available on the demo https://github-fxeygh.stackblitz.io/
-
Angular version: 7.1.4
-
PrimeNG version: 7.0.3
-
Browser: Chrome 71.0.3578.98 Firefox 64.0
-
Language: TypeScript 3.1.6
DialogService by design one Dialog so for nesting, inner components needs to have its own service injected.
Thanks a lot for the answer, adding the DialogService into providers of the inner component solved the problem. Cheers
Hello, cuneytcalishkan Could you please tell me more detail about it. I had same problem, so I hope your kind help.
Thanks
Hello @wanginternnect,
you just need to add the DialogService into the list of providers of your component that you are using the dialog service. This will inject a new instance of the dialog service.
e.g. Component1 opens Popup1, and you need to open another popup, Popup2, from within Popup1. You just need to put the DialogService into the providers array of your Popup1 component.
Hello, @cuneytcalishkan Thanks for your kind reply. I have created dialog with DialogService, and on this dialog, I have created another dialog with dialogservice. Second dialog is closed by this.dynamicDialogRef.close(); But first dialog is not closed by this.dynamicDialogRef.close();- it works nothing. If you have any solution, please help me. Sincerely.
@wanginternnect just check the stackblitz I provided in the description for the code sample. Current version is actually working because the DialogComponent has its providers: [DialogService] which injects its own instance.
You just have to add " providers: [DialogService] " to your "another dialog" and it should be fine
Hello, @cuneytcalishkan Thanks again. I have added provider, but it is not working. Could you please show me source code of stackblitz demo?
Sincerely
It is on the editor link up in the description, you should be able to access it: https://stackblitz.com/edit/github-fxeygh
Hi, @cuneytcalishkan Thank you very much. You have posted great article here. I highly recommend you. I hope to connect with you for a long time. Thanks again.
This will not work if I try to subscribe to the close event of both the dialogues.
I am still having this issue, in my scenario, my application has a few modal openings from a couple of places in the application so I put those dialogs into my header component and opened them using data services, I have 2 dialogs named service-dialog and item-dialog both are opening from the header component. service-dialog and item-dialog has their own providers: [DialogService], in there component please help me here
@Component({ selector: 'app-header', templateUrl: './header.component.html', styleUrls: ['./header.component.scss'], providers: [DialogService], }) export class HeaderComponent implements OnInit, OnDestroy { openServiceDialog() { this.dialogService.open(ServiceDialog, { }); }
openItemDialog() {
this.dialogService.open(ItemDialog, { });
}
}
Hi, I landed here because DynamicDialogRef.close() didn't work for me at all, even with a single popup. I've achieved to get it work thanks to this discussion but it is misleading in the documentation. The ProductListDemo in the documentation that is inserted into DynamicDialog has DynamicDialgRef in providers:
@Component({
selector: 'product-list-demo',
templateUrl: './productlistdemo.html',
providers: [DynamicDialogRef]
})
export class ProductListDemo implements OnInit {
However, there should be the DialogService put in provider array, not the DynamicDialgRef. I suggest changing it in the documentation (v16.2.0)
Hi, I landed here because DynamicDialogRef.close() didn't work for me at all, even with a single popup. I've achieved to get it work thanks to this discussion but it is misleading in the documentation. The ProductListDemo in the documentation that is inserted into DynamicDialog has DynamicDialgRef in providers:
@Component({ selector: 'product-list-demo', templateUrl: './productlistdemo.html', providers: [DynamicDialogRef] }) export class ProductListDemo implements OnInit {However, there should be the DialogService put in provider array, not the DynamicDialgRef. I suggest changing it in the documentation (v16.2.0)
Indeed, the documentation is misleading, it should be the DialogService put in provider array instead of DynamicDialgRef.
For those having trouble with this, you don't need to add DynamicDialogRef or DialogService, if you do that you'll be adding a new and different instance to the one you already have. Don't add it to the providers array, just inject it into the constructor and you're done. Works like a charm!