角度5 - 角度材料在组件中不起作用

时间:2018-04-27 14:28:45

标签: angular angular-material angular-material2

我正在我的角度5应用程序中实现角度材质。 当我在我的app.module.ts中导入时 - 我没有问题,但是当我在我的页面中使用时.component.html无法显示以下错误:

'Uncaught Error: Template parse errors:
'mat-toolbar-row' is not a known element:
'1. If 'mat-toolbar-row' is an Angular component, then verify that it is part of this module.
'2. If 'mat-toolbar-row' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("r="let paragraph of paragraphs">{{paragraph}}</p>
    <mat-toolbar color="primary">
        [ERROR ->]<mat-toolbar-row>
          <span>MyMaterial</span>
      "): ng:///SharedComponentsModule/FollowUpComponent.html@35:12
'mat-toolbar' is not a known element:
1. If 'mat-toolbar' is an Angular component, then verify that it is part of this module.
2. If 'mat-toolbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <h6>Answer:</h6>
    <p *ngFor="let paragraph of paragraphs">{{paragraph}}</p>
    [ERROR ->]<mat-toolbar color="primary">
        <mat-toolbar-row>
          <span>MyMaterial</span>
"): ng:///SharedComponentsModule/FollowUpComponent.html@34:8
at syntaxError (compiler.js:485)
at TemplateParser.parse (compiler.js:24668)
at JitCompiler._parseTemplate (compiler.js:34621)
at JitCompiler._compileTemplate (compiler.js:34596)
at eval (compiler.js:34497)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:34497)
at eval (compiler.js:34367)
at Object.then (compiler.js:474)
at JitCompiler._compileModuleAndComponents (compiler.js:34366)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; 
import { MatButtonModule, MatToolbarModule } from '@angular/material';

@NgModule({
   imports: [MatButtonModule, MatToolbarModule],
   exports: [MatButtonModule, MatToolbarModule]
})
export class MaterialModule { }

我已导入MaterialModule并已包含在imports的{​​{1}}中。

这是我的组件的HTML:

app.module.ts

1 个答案:

答案 0 :(得分:-1)

有完全相同的问题。 我用大锤的方法来解决它。 我也不喜欢它,但它也适合你。

npm install --save @angular/material @angular/cdk
npm install --save angular/material2-builds angular/cdk-builds