首页 > 解决方案 > ERROR 错误:StaticInjectorError(AppModule)[MatToolbar -> ElementRef]

问题描述

第一天使用@angular/material 时出现错误。像这样的版本:

"dependencies": {
    "@angular/animations": "^6.0.3",
    "@angular/cdk": "^6.2.0",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/material": "^6.2.0",
...
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.6",
    "@angular/cdk": "^6.2.0",
    "@angular/cli": "~6.0.7",
    "@angular/compiler-cli": "^6.0.3",
    "@angular/language-service": "^6.0.3",
    "@angular/material": "^6.2.0",
    "hammerjs": "^2.0.8",
    "typescript": "~2.7.2"
  }

我在 app.module.ts 中导入模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// the third modules
import { LayoutModule } from '@angular/cdk/layout';
import { MatToolbarModule } from '@angular/material/toolbar';
import 'hammerjs';
import { HeaderComponent } from './header/header.component';
import { BaseDataComponent } from './base-data/base-data.component';
@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    BaseDataComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    LayoutModule,
    MatToolbarModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

然后我在html中使用mat-toolbar,但是当我在浏览器中运行它时,我在控制台中遇到错误: 我搜索了很多但仍然有问题的错误 ,有人可以帮助我吗?请!

标签: javascriptangular

解决方案


推荐阅读