“ mat-tree”不是已知元素:

时间:2020-06-08 14:11:12

标签: javascript angular angular-material

当我尝试添加material.angular的expmle树时,我得到并出错

src / app / features / itemmonitor / data-options-tree / data-options-tree.component.html:1:1中的

ERROR-错误NG8001:“ mat-tree”不是已知元素: 1.如果“ mat-tree”是Angular组件,则请验证它是否是此模块的一部分。 2.如果“ mat-tree”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”以禁止显示此消息。

data-options-tree.component.spec.ts

<mat-tree>
  <mat-tree-node> parent node </mat-tree-node>
  <mat-tree-node> -- child node1 </mat-tree-node>
  <mat-tree-node> -- child node2 </mat-tree-node>
</mat-tree>

item-monitor.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DataOptionsTreeComponent } from './data-options-tree/data-options-tree.component';
import { MatTreeModule } from '@angular/material/tree';

@NgModule({
  declarations: [DataOptionsTreeComponent],
  imports: [
    CommonModule,
    MatTreeModule,
  ],
})
export class ItemMonitorModule { }

我的package.json依赖项

 "dependencies": {
    "@angular/animations": "~9.1.9",
    "@angular/cdk": "~9.2.4",
    "@angular/common": "~9.1.9",
    "@angular/compiler": "~9.1.9",
    "@angular/core": "~9.1.9",
    "@angular/forms": "~9.1.9",
    "@angular/material": "~9.2.4",
    "@angular/platform-browser": "~9.1.9",
    "@angular/platform-browser-dynamic": "~9.1.9",
    "@angular/router": "~9.1.9",
    "rxjs": "~6.5.5",
    "thrift": "git+https://github.com/apache/thrift.git",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.3"
  },

1 个答案:

答案 0 :(得分:0)

rm -rf node_modules/
npm install

这对我有用。