Я хотел закрыть все мои диалоги (mat-dialog, модальные окна начальной загрузки и приятные оповещения) при выходе из системы в Angular. Вот как это было сделано в AngularJS (версия 1.5):
function logout() {
//hide $mdDialog modal
angular.element('.md-dialog-container').hide();
//hide any open $mdDialog modals & backdrop
angular.element('.modal-dialog').hide();
angular.element('md-backdrop').remove();
//hide any open bootstrap modals & backdrop
angular.element('.inmodal').hide();
angular.element('.fade').remove();
//hide any sweet alert modals & backdrop
angular.element('.sweet-alert').hide();
angular.element('.sweet-overlay').remove();
}
Как я могу сделать это в Angular? Использование $('.mat-dialog-container')
или $('.inmodal')
не дает мне возможности сделать hide()
или close()
Я пытался сделать это, но не могу получить ссылку на элемент:
import { ElementRef, Injectable, ViewChild } from '@angular/core';
import { MatDialog, MatDialogContainer, MatDialogRef } from '@angular/material';
export class MyClass
{
@ViewChild('.mat-dialog-container') _matDialog: ElementRef;
@ViewChild('.mat-dialog-container') _matDialogRef:MatDialogRef<MatDialog>;
constructor() { }
function logout()
{
//access the dialogs here
}
}