2017-07-17 97 views
0

我知道這是重複的問題,但沒有列出的解決方案幫助我。我收到以下錯誤控制檯:Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming角材2找不到核心主題

我已經這樣做:

等等。我似乎已經失去了標籤。

現在讓我感興趣的是我從這裏看到的樣式加載。

Screenshot

原來是類材料檢查:mat-theme-loaded-marker

但我仍然無法讓它加載。同樣的錯誤。

我的AppModule如下:

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { RouterModule, Routes } from '@angular/router'; 
import 'hammerjs'; 
import { LoginComponent } from './components/login/app'; 
import { CookieService } from 'ngx-cookie-service'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
import { MaterialModule } from '@angular/material'; 

const appRoutes: Routes = [ 
    {path: 'login', component: LoginComponent}, 
    { path: '**', component: LoginComponent } 
]; 

@NgModule({ 
    declarations: [ 
    LoginComponent 
    ], 
    imports: [ 
    FormsModule, 
    HttpModule, 
    BrowserModule, 
    BrowserAnimationsModule, 
    RouterModule.forRoot(
     appRoutes, 
     { enableTracing: true } // <-- debugging purposes only 
    ), 
    MaterialModule 
    ], 
    providers: [ CookieService], 
    bootstrap: [ LoginComponent ] 
}) 
export class AppModule { } 

PS:我是新來的角4.

+0

順便說一句:你不再做'MaterialModule'。相反,您只需包含您需要的組件的模塊,如「MdButtonModule」等等。看看這裏:[入門](https://material.angular.io/guide/getting-started)。 – pzaenger

+0

「樣式表導入」的順序是什麼?更新css包括你的帖子 – Aravind

+0

@pzaenger是的,我最初嘗試過,同樣的錯誤。因此堅持這一點。 –

回答

-1

與材料設計開發角度2,我們需要使用一些默認的CSS從其他明智的原料成分它會在您的瀏覽器中顯示控制檯錯誤,如找不到Angular Material核心主題。。爲了避免這些問題,我們需要在您的材質組件中使用其中一個默認主題。從下面的圖片中,您可以觀察到node_module中的預構建主題。 enter image description here

。我正在導入我的styles.css文件中的一個主題。請查看下面的屏幕截圖。然後重新加載頁面,然後您可以在瀏覽器控制檯中看到沒有錯誤消息顯示。我希望這會對你有所幫助。 enter image description here

+0

我的設置是相同的,除了自定義樣式。問題不是CSS文件,它被加載,但我猜材料檢查後。 這是我的css:http://imgur.com/a/WB0Xa –

+0

忘了說,還是一樣的錯誤。在閱讀您的答案後,我添加了「body」風格。 –

+0

由於以下原因,我下調了您的答案:正在加載的css顯示在問題圖像中;導入命令在上面的問題中提到,並在註釋中我指定它是唯一的命令在CSS文件中。 –