无法向角度模块添加材料

时间:2020-03-25 09:20:34

标签: angular-material angular9

我试图找到如何添加角材料以将角分为多个模块。它只能在root用户中工作,而不能在模块中工作。

ng add @angular/material

package.json

"dependencies": {
    "@angular/animations": "^9.1.0-rc.2",
    "@angular/cdk": "^9.1.3",
    "@angular/common": "~9.1.0-rc.1",
    "@angular/compiler": "~9.1.0-rc.1",
    "@angular/core": "~9.1.0-rc.1",
    "@angular/forms": "~9.1.0-rc.1",
    "@angular/material": "^9.1.3",
    "@angular/platform-browser": "~9.1.0-rc.1",
    "@angular/platform-browser-dynamic": "~9.1.0-rc.1",
    "@angular/router": "~9.1.0-rc.1",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.0-rc.0",
    "@angular/cli": "~9.1.0-rc.0",
    "@angular/compiler-cli": "~9.1.0-rc.1",
    "@angular/language-service": "~9.1.0-rc.1",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }

home.module.ts

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '../../../node_modules/@angular/platform-browser/animations';
import { HomeRoutingModule } from './home-routing.module';
import { HomeComponent } from './home/home.component';
import { MatCardModule } from '@angular/material/card';
@NgModule({
  declarations: [HomeComponent],
  imports: [
    CommonModule,
    HomeRoutingModule,
    MatCardModule,
    BrowserAnimationsModule,
  ],
})
export class HomeModule { }

和我的home.component.html

<p>home works!</p>
<mat-card>Simple card</mat-card>

它给我错误:

ERROR in src/app/home/home/home.component.html:2:1 - error NG8001: 'mat-card' is not a known element:
1. If 'mat-card' is an Angular component, then verify that it is part of this module.
2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component

禁止显示此消息。

我试图将物料卡模块导入到app.module.ts中。但是,它仅适用于根组件,不适用于模块。

0 个答案:

没有答案