2017-05-05 20 views
0

我目前使用的是角度4,並且我遵循關於如何使用角度材質的鏈接here。這是我迄今所做的:找不到Angular Material核心主題。大多數材質組件可能無法按預期工作

app.module.ts

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

imports: [ 
    BrowserAnimationsModule 
    ], 

我在的index.html包括主題風格

<head> 
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 
    <link href="../node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet"> 
</head> 

組件

<md-sidenav-container> 
    <md-sidenav> 
    un idee 
    </md-sidenav> 

    <!-- primary content --> 
</md-sidenav-container> 

但我得到的錯誤:

Unhandled Promise rejection: Template parse errors: 
'md-sidenav' is not a known element: 
1. If 'md-sidenav' is an Angular component, then verify that it is part of this module. 
2. If 'md-sidenav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 

及以下警告

Could not find Angular Material core theme. Most Material components may not work as expected 

任何人都可以指出我在做什麼錯?

回答

1

你缺少MdSidenavModule進口和添加它作爲一個依賴於你的AppModule

import { MdSidenavModule} from '@angular/material' 

imports: [ 
    BrowserAnimationsModule, MdSidenavModule 
    ], 

還要確保,下面一行是存在於你的systemjs配置文件

'@angular/material': 'npm:@angular/material/bundles/material.umd.js', 

如果你正面臨BrowserAnimationsModule, NoopAnimationsModule錯誤。請參閱本post

更新:路徑進行更改,按您的版本

+0

我進口'MdSidenavModule':對於CLI,與下面的路徑

"paths": { "@angular/material": ["../../dist/packages/material/public_api"] } 

注意更新tsconfig-build.json文件。但是,它導致編譯錯誤「沒有導出的成員」。 我正在使用cli,所以我沒有systemjs配置文件。 – edkeveked

+0

對不起,但似乎我沒有tsconfig-build文件。我有tsconfig.json但不是你提到的那個 – edkeveked

+0

是的。 { 「的baseUrl」:改變,因爲我在該文件中 – Aravind