Мой .open () в диалоге материалов не работает в Angular 6. Я получаю ошибку:
ОШИБКА TypeError: Невозможно прочитать свойство 'open' из неопределенного
Что может быть не так? Кажется, что импорт MatDialog не распознается
Родительский компонент:
import { Component, OnInit, Input, Inject } from '@angular/core';
import { AuthService } from "../../services/auth.service";
import { SiteService } from "../../services/site.service";
import { MonitoringPointService } from "../../services/monitoring-point.service";
import { Router, ActivatedRoute } from '@angular/router';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
import { DialogComponent } from '../dialog/dialog.component';
@Component({
selector: 'app-site-settings',
templateUrl: './site-settings.component.html',
styleUrls: ['./site-settings.component.css']})
export class SiteSettingsComponent implements OnInit {
constructor(public dialog: MatDialog, private router: Router, private route: ActivatedRoute, public authService: AuthService, public siteService: SiteService,public monitoringPointService: MonitoringPointService ) { }
openDialog(): void {
const dialogRef = this.dialog.open(DialogComponent, {
width: '250px',
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
ngOnInit() {
...
}
}
Компонент диалога:
import { Component, OnInit, Inject } from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { SiteSettingsComponent } from '../site-settings/site-settings.component';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.css']
})
export class DialogComponent implements OnInit {
constructor( public dialogRef: MatDialogRef<DialogComponent>) { }
ngOnInit() {}
onNoClick(): void {
this.dialogRef.close();
}
}