这个问题在这里已有答案:
我正在用角度6和材料制作一个小教程 . 我的代码:
HTML:
<mat-toolbar>
<span>Angular 6 Mean Stack Sample</span>
</mat-toolbar>
<div>
<router-outlet></router-outlet>
</div>
APP-module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {MatToolbarModule} from '@angular/material';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ListComponent } from './components/list/list.component';
import { CreateComponent } from './components/create/create.component';
import { EditComponent } from './components/edit/edit.component';
@NgModule({
declarations: [
AppComponent,
ListComponent,
CreateComponent,
EditComponent,
MatToolbarModule
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
在html部分我从我的ide中得到这个错误:
ng:'mat-toolbar'不是已知元素:如果'mat-toolbar'是Angular组件,则验证它是否是此模块的一部分 .
当我启动程序时,一切正常,但我的屏幕上什么都没有 . 来自Web控制台的错误是:
错误:模块'AppModule'声明的意外模块'MatToolbarModule' . 请添加@ Pipe / @ Directive / @ Component注释 .
我重新安装了所有东西,从头开始项目,但没有任何帮助 . 如果有人能帮助我,我会很棒,
谢谢,
汤姆
1 回答
将模块
MatToolbarModule
从declarations
数组移动到imports
数组 .Modules
只能导入,声明为components
.