I am trying to use MdDialog
from the material module of Angular 2. I have a component that I am trying to use a dialog in shown below:
import { Component, OnInit } from '@angular/core';
import { Aircraft } from '../shared/aircraft';
import { AircraftService } from '../shared/aircraft.service';
import { MdDialog, MdDialogRef } from '@angular/material';
import { NewAircraftDialogComponent } from '../new-aircraft-dialog/new-aircraft-dialog.component';
@Component({
selector: 'app-statusboard',
templateUrl: './statusboard.component.html',
styleUrls: ['./statusboard.component.css']
})
export class StatusboardComponent implements OnInit {
aircrafts: Aircraft[] = [];
constructor(private aircraftService: AircraftService,
public dialog: MdDialog) { }
ngOnInit(): void {
this.aircraftService.getAircrafts()
.then(aircrafts => this.aircrafts = aircrafts);
}
openNewAircraftDialog(): void {
let dialogRef = this.dialog.open(NewAircraftDialogComponent, {
width: '300px'
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
}
And the dialog component is shown below:
import { Component, OnInit } from '@angular/core';
import { Aircraft } from '../shared/aircraft';
import { AircraftService } from '../shared/aircraft.service';
import { MdDialogRef } from '@angular/material';
@Component({
selector: 'app-new-aircraft-dialog',
templateUrl: './new-aircraft-dialog.component.html',
styleUrls: ['./new-aircraft-dialog.component.css']
})
export class NewAircraftDialogComponent implements OnInit {
newAircraft: Aircraft;
constructor(private aircraftService: AircraftService,
public dialogRef: MdDialogRef<NewAircraftDialogComponent>) { }
ngOnInit() {
}
onSubmitClick(): void {
this.dialogRef.close();
}
onCloseClick(): void {
this.dialogRef.close();
}
}
But I am getting an error in the console:
Error: Uncaught (in promise): Error: No provider for MdDialog!
Looking around online, it says to add "entryComponents: [NewAircraftDialogComponent]"
to NgModule
. I did, but that hasn't solved the issue.