Not able to close modal dialog using dialogRef.close()
See original GitHub issueI am opening Modal popup in Angular 4 using Material. whereas it is opening properly but I am not able to close it using dialogRef.close(). I am opening AdminComponent as a popup by clicking on button which is present on Home.Component.html.
Admin.Component.ts- `import {MdDialog} from ‘@angular/material’; import {MdDialogRef} from ‘@angular/material’;
export class AdminComponent implements OnInit {
constructor( public dialogRef:MdDialogRef <AdminComponent>,
private emergencycontacts: EMTServiceService) { }
closeModal() {
console.log(‘closing’);
this.dialogRef.close();
}
}`
Admin.Component.html-
<td md-dialog-actions> <button md-raised-button (click)="closeModal()" class="btncancel" >Cancel</button></td>
Please help
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:23 (7 by maintainers)
Top Results From Across the Web
MatDialog dialog from Angular Material is not closing
You have this error because you open the dialog outside the NgZone. An easy fix is to import the NgZone in the constuctor:....
Read more >How to Prevent closing of modal Dialog in Angular Dialog ...
In the following sample, the dialog is closed when you enter the username value with minimum 4 characters. Otherwise, it will not be...
Read more >Angular Material Dialog not closing when I navigate to a new ...
I haven't worked with angular material in a long time, and I'm on mobile. It's possible that component doesn't have the same dialog...
Read more >mat-dialog-close not working - You.com | The AI Search ...
I tried using a setTimeOut in the dialogRef.afterOpened() to close the dialog from the parent but the behaviour is the same. For one...
Read more >Routing to Angular Material Dialogs | by John Crowson | ngconf
Many Angular developers chose to use Angular Material because it provides a huge set of ... but it does not return to “/home”...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@krisparis can you try this in
ErrorDialogContainerComponent
?@krisparis I think everything on Angular and Angular Material’s end is working as intended, so I wouldn’t await a fix (maybe a docs improvement here at best).
Every use case is different - I think the expected use of the ErrorHandler is to facilitate logging or extra ajax calls or similar, which don’t need to operate within the angular zone. You’ve chosen to bring the error callback into your components (material dialog), so you should do so inside the zone. If you are using
errorEventService.changeEmitted$
exclusively for UI updates, I would suggest this:But also I have only a moderate understanding of how zones work and should be utilized so take it with a grain of salt 😄