[英]Errors while using Angular-material2
I just begin to use Anuglar-material2 in my project, however, I just cannot import any component correctly. 我只是在项目中开始使用Anuglar-material2,但是,我无法正确导入任何组件。 After I import some material modules in my app.module.ts, I'm getting errors like following: 在我的app.module.ts中导入一些材料模块后,出现如下错误:
uncaught Error: Unexpected value 'MdButtonModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.es5.js:1690)
at compiler.es5.js:15383
at Array.forEach (<anonymous>)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:15366)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._loadModules (compiler.es5.js:26796)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._compileModuleAndComponents (compiler.es5.js:26769)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler.compileModuleAsync (compiler.es5.js:26698)
at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_._bootstrapModuleWithZone (core.es5.js:4535)
at PlatformRef_.webpackJsonp.../../../core/@angular/core.es5.js.PlatformRef_.bootstrapModule (core.es5.js:4521)
at Object.../../../../../src/main.ts (main.ts:11)
here's my app.module.ts 这是我的app.module.ts
import 'hammerjs';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { SearchModule } from './search/search.module';
import { PostModule } from './post/post.module';
import { UserModule } from './user/user.module';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import {MdButtonModule, MdCheckboxModule} from '@angular/material';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NavTopComponent } from './nav-top/nav-top.component';
import { AuthService } from './core/auth.service';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
NavTopComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MdButtonModule,
MdCheckboxModule,
BsDropdownModule.forRoot(),
SearchModule,
PostModule,
UserModule,
AppRoutingModule
],
exports: [
],
providers: [AuthService],
bootstrap: [AppComponent]
})
export class AppModule { }
I did exactly every steps that included in official documentations of Material2. 我确实做了Material2官方文档中包含的每个步骤。
Thanks a lots for your kind advice! 非常感谢您的建议!
But I just solve this problem by deleting the whole node_modules folder and reinstall all packages using npm install . 但是我只是通过删除整个node_modules文件夹并使用npm install重新安装所有软件包来解决此问题。
When I run ng serve again, such error just disappeared. 当我再次执行ng serve时,这种错误就消失了。 I don't know the reason, but hope this can help others who may have the same problem! 我不知道原因,但是希望这可以帮助其他可能遇到相同问题的人!
BTW, my Angular version is 4.0, Angular-cli version is 1.2.1 and Angular-material version is 2.0.0 顺便说一句,我的Angular版本是4.0,Angular-cli版本是1.2.1,Angular-material版本是2.0.0
Thanks again! 再次感谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.