模板解析错误:"mat-icon"不是已知元素 [英] Template parse errors: 'mat-icon' is not a known element
本文介绍了模板解析错误:"mat-icon"不是已知元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Angular CLI和v.5.2.5角材料 并尝试使用
I'm working with Angular CLI and angular material v.5.2.5 and trying to use
mat-icon-button
mat-icon-button
但是控制台产生了这样的错误:
but such an error produced by the console:
未捕获的错误:模板解析错误:未知'mat-icon' 元素...
Uncaught Error: Template parse errors: 'mat-icon' is not a known element...
如果我使用
垫子升起按钮
mat-raised-button
一切正常 无法解决该问题
everything works fine cannot figure out how to solve that
index.html
index.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
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.
The MatIconModule is missing from your imports.
imports: [
BrowserModule,
FormsModule,
HttpModule,
MatButtonModule,
MatIconModule, // <-- here
],
这篇关于模板解析错误:"mat-icon"不是已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文