Angular Material 2无法找到核心主题

时间:2017-07-17 07:38:08

标签: css angular angular-material2

我知道这是一个重复的问题,但列出的解决方案都没有帮助我。我在控制台中收到以下错误: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

我已经做过的事情:

还有其他人。我似乎已经失去了标签。

现在引起我兴趣的是我从这里看到了加载的样式。

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的新手。

1 个答案:

答案 0 :(得分:-1)

使用材质设计开发Angular 2,我们需要使用材质组件中的一些默认css,否则它会在浏览器中显示控制台错误,如无法找到Angular Material核心主题。。要避免这些问题我们需要使用材质组件中的一个默认主题。从下面的图像中,您可以在node_module中观察 4 预构建它们。enter image description here

。我正在导入 styles.css 文件中的一个主题。请查看下面的屏幕截图。重新加载页面后,您可以看到浏览器控制台中没有显示错误消息。我希望它会对你有所帮助。enter image description here