angular - 模板解析错误:“mat-icon”不是已知元素
问题描述
我正在使用 Angular CLI 和 angular material v.5.2.5 并尝试使用
垫子图标按钮
但是控制台产生了这样的错误:
未捕获的错误:模板解析错误:'mat-icon' 不是已知元素...
如果我使用
垫凸起按钮
一切正常无法弄清楚如何解决
索引.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Todo</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic"
rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<app-root></app-root>
</body>
</html>
main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { MatButtonModule } from '@angular/material/button';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MatButtonModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
解决方案
您的导入中缺少 MatIconModule。
imports: [
BrowserModule,
FormsModule,
HttpModule,
MatButtonModule,
MatIconModule, // <-- here
],
推荐阅读
- php - 在连接到另一个本地 PHP 脚本的 FTP 服务器上执行 PHP 脚本
- r - RStudio 'line by line' 运行在 Linux 中有效,但在 Windows 中或使用 knitr 时无效
- python - 将列表拆分为知道结束索引的列表
- android - 为什么这个问题发生在firebase依赖中?
- python - 如何聚合文本文件的出现然后绘制它Python
- python - Scikit 中的内核技巧和内核 K-Means
- openapi-generator - 从 openapi 从 C# 生成时在 DataMember 中生成不同的名称
- php - 'require' 绝对路径不起作用(作曲家)
- json - 在使用 DRF python 为 API 创建 JSON 响应时面临挑战
- ios - 无法使用 SharedSecret 建立 VPN 连接