错误错误:StaticInjectorError(AppModule)[MatToolbar - > ElementRef]

时间:2018-06-04 15:58:02

标签: javascript angular

我第一天使用@ 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,但是当我在浏览器中运行它时,我在控制台中出错: the error 我googing了很多,但仍然有问题,任何人都可以帮助我吗? PLZ!

0 个答案:

没有答案