2017-10-09 40 views
0

當我使用md-form-field標記時,出現如下所述的一個錯誤。不工作的md-form-field並出現錯誤

錯誤是:

ERROR Error: Found the synthetic property @transitionMessages. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. 
    at checkNoSyntheticProp (platform-browser.es5.js:2930) 
    at DefaultDomRenderer2.webpackJsonp.../../../platform-browser/@angular/platform-browser.es5.js.DefaultDomRenderer2.setProperty 

但我導入BrowserAnimationsModule.module.ts文件,但我得到錯誤的波紋管描述:

core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. 
Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. 
    at new BrowserModule (platform-browser.es5.js:4161) 
    at _createClass (core.es5.js:9528) 

如何解決呢? 我的材料版本是@angular/[email protected]@angular/[email protected]

home.html的文件

<md-form-field> 
    <input type="text" mdInput > 
</md-form-field> 

app.module.ts文件

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { RouterModule } from '@angular/router'; 
import { CommonModule } from './common/common.module'; 
import { AppComponent } from './app.component'; 
import { AuthLayoutComponent } from './common/services/index.service'; 
import { AppRoutesModule } from './app.routing'; 
import { 
    SessionModule 
} from './session/session.module'; 
import { DashboardComponent } from './dashboard/dashboard.component'; 
import { AuthService } from './common/services/authservice'; 
import { AuthGuard } from './common/services/auth-guard.service'; 
import { SourcesModule } from './sources/sources.module'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 
import { MaterialModule } from '@angular/material'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    AuthLayoutComponent, 
    DashboardComponent 
    ], 
    imports: [ 
    CommonModule, 
    BrowserModule, 
    BrowserAnimationsModule, 
    FormsModule, 
    ReactiveFormsModule, 
    AppRoutesModule, 
    MaterialModule, 
    SessionModule, 
    SourcesModule 
    ], 
    providers: [AuthGuard, AuthService], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
+0

Ayaz,你揭露你的祕密API密鑰... –

回答

0

添加BrowserAnimationsModuleNoopAnimationsModule你的模塊的imports: []部分。請確保安裝此軟件包:npm install --save @angular/animations

import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; 

import {NoopAnimationsModule} from '@angular/platform-browser/animations'; 

將爲您可以導入模塊。這裏是official documentation

+0

Thankz伊戈爾回覆我。是的,我安裝了這個軟件包,我的版本是@ angular/animations @ 4.0.0。 –

+0

@ayazkodiya請接受如果它爲你工作的答案 –

+0

當我導入BrowserAnimationsModule或NoopAnimationsModule然後錯誤發生爲FruntEnd控制檯作爲波紋管: 錯誤:未捕獲(承諾):錯誤:BrowserModule已被加載。如果您需要從惰性加載模塊訪問常見指令(如NgIf和NgFor),請改爲導入CommonModule。 錯誤:BrowserModule已被加載。如果您需要從惰性加載模塊訪問常見指令(如NgIf和NgFor),請改爲導入CommonModule。 在新的BrowserModule(platform-b​​rowser.es5.js:4161) –

相關問題