错误“mat-dialog-content"不是已知元素 [英] Error 'mat-dialog-content' is not a known element
问题描述
我正在尝试使用 angular-material 创建登录表单.我正在使用 @angular/material": "^7.3.0
.
I am trying to create a login form using angular-material. I am using @angular/material": "^7.3.0
.
在 app.module.ts
中,我导入了以下内容并将它们也放入了导入数组中,
In app.module.ts
i have imported the following and placed them in the imports array as well,
import {
MatToolbarModule, MatFormFieldModule, MatInputModule,
MatOptionModule, MatSelectModule, MatIconModule,
MatButtonModule, MatCardModule, MatTableModule,
MatDividerModule, MatSnackBarModule
} from '@angular/material';
在 message.components.ts
我有以下内容
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material';
import { Component, OnInit, Inject, Injectable } from '@angular/core';
@Component({
selector: 'app-message',
templateUrl: './message.component.html',
styleUrls: ['./message.component.css']
})
export class MessageComponent implements OnInit {
constructor(private dialogRef: MatDialogRef<MessageComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
public closeMe() {
this.dialogRef.close();
}
ngOnInit() {
}
}
在我的模板 message.component.html 中,
In my template message.component.html i have,
<h1 mat-dialog-title>Message</h1>
<mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions>
<button mat-raised-button (click)="closeMe()">Close</button>
</mat-dialog-actions>
我收到了 mat-dialog-actions & 的错误垫对话框内容,
I am getting the errors for mat-dialog-actions & mat-dialog-content,
'mat-dialog-content' is not a known element:
'mat-dialog-actions' is not a known element:
根据文档angular-material,这两个指令都可用.代码中可能有什么问题?提前致谢.
As per the documentation angular-material both directives are available. What could be wrong in the code ? Thank you in advance.
推荐答案
看起来你忘记将 MatDialogModule
导入你的 AppModule
(至少我没有请在提供的导入列表中查看).
为了将来参考,API 文档选项卡的第一行将告诉您模块) 你需要导入.
It looks like you forgot to import the MatDialogModule
into your AppModule
(at least I don't see it in the list of imports provided).
For future reference, the first line of the API documentation tab will tell you the module(s) you need to import.
这篇关于错误“mat-dialog-content"不是已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!