【发布时间】:2017-07-17 16:19:14
【问题描述】:
我知道这是一个重复的问题,但列出的解决方案都没有帮助我。我在控制台中收到以下错误: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
我已经做了什么:
- 在 angular-cli.json 中添加样式键 Suggested Here
- 尝试了 CSS Suggested Here 的真实路径
还有其他几个。我似乎丢失了标签。
现在让我感兴趣的是我已经加载了从这里看到的样式。
材料检查的类也是如此: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:我是 Angular 4 的新手。
【问题讨论】:
-
顺便说一句:你不要再做
MaterialModule了。相反,您只需包含所需组件的模块,例如MdButtonModule等等。看这里:Getting started. -
stylesheets import的序列是什么?将 CSS 更新到您的帖子中 -
@pzaenger 是的,我最初尝试过,同样的错误。因此坚持这一点。
-
@Aravind 只有一个导入。没有别的了。
-
伙计们,我让它工作了,但它看起来更像是一个黑客而不是工作。我将样式表 CSS 添加到
assets文件夹中,将其位置添加到angular-cli.json中,瞧,它可以工作了。现在真正的问题是,为什么这行得通,而文档中提供的方法却行不通?
标签: css angular angular-material2