首页 文章

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

提问于
浏览
0

我正在我的角度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 app.module.ts 中 .

这是我的组件的HTML:

<mat-toolbar color="primary">
  <mat-toolbar-row>
    <span>MyMaterial</span>
    <span class="example-spacer"></span>
    <button mat-button>About</button>
    <button mat-button>Services</button>
    <button mat-button>Contact</button>
  </mat-toolbar-row>
</mat-toolbar>

1 回答

  • -1

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

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

相关问题