【发布时间】:2020-11-15 01:47:09
【问题描述】:
我知道这个问题是重复的 (this)。但我有问题。
我在 AppModule 的导入部分添加了MatDialogModule。
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MatDialogModule,
MatButtonModule,
AppRoutingModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我的对话内容:
<h2 mat-dialog-title>Install Angular</h2>
<mat-dialog-content class="mat-typography">
<h3>Develop across all platforms</h3>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install</button>
</mat-dialog-actions>
当我想打开对话框时:
constructor(public dialog: MatDialog) {}
openDialog() {
const dialogRef = this.dialog.open(CourseAcitonComponent);
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`);
});
}
我收到以下错误:
1-
If 'mat-dialog-content' is an Angular component, then verify that it is part of this module.
2-
Can't bind to 'mat-dialog-close' since it isn't a known property of 'button'.
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install</button>
【问题讨论】:
-
无论您从哪里调用 openDialog 方法,它是否在 appModule 上下文中?
-
@alou - 谢谢。是的。它在 appModule 上下文中