angular-material - 无法向角度模块添加材料
问题描述
我试图找到如何添加角度材料以将角度划分为模块。它仅适用于根目录,但不适用于模块。
ng add @angular/material
包.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。但是它只适用于根组件,而不是模块。
解决方案
推荐阅读
- laravel - Laravel IoC Container - 绑定一个单例,然后在没有原始参数时返回它
- .net - 如何将事件调用中的数据返回到 Blazor 中的 JS 互操作方法
- javascript - 如何在四列/网格中显示 HTML 表格
- git - 使用 Git-SVN 取消跟踪目录
- google-apps-script - 有没有办法通过脚本设置 Google 文件夹/文件的所有者?
- xml - 无法为我的 bean XML 配置文件获取 c-namespace 和 p-namespace
- google-play - 如何使用 android management api 静默推送 apk 并通过 android 设备策略安装它?
- python - 没有这样的文件或目录:'builtup/build0.jpg'
- c# - Azure Functions:绑定到 DocumentClient 与静态实例 - 推荐什么?
- mysql - 带有@ORM\Column 的 Symfony 4 Doctrine 引发 MySQL 1054 错误