错误:无法绑定到“ dataSource”,因为它不是“ mat-tree”的已知属性

时间:2018-06-25 15:46:48

标签: angular typescript angular-material angular-material2 angular6

我在文档中添加了从https://material.angular.io/components/tree/overview中检索到的示例(可以看到该示例[https://stackblitz.com/angular/arbvompqpmg?file=main.ts]),但它引发了以下错误:

Can't bind to 'dataSource' since it isn't a known property of 'mat-tree'.
1. If 'mat-tree' is an Angular component and it has 'dataSource' input, then verify that it is part of this module.
2. If 'mat-tree' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

我都添加了

import {CdkTreeModule} from '@angular/cdk/tree';

import {MatTreeModule} from '@angular/material';

我当前的版本是:

"@angular/animations": "^6.0.6",
"@angular/cdk": "^6.3.0",
"@angular/common": "^6.0.6",
"@angular/compiler": "^6.0.6",
"@angular/core": "^6.0.6",
"@angular/forms": "^6.0.6",
"@angular/http": "^6.0.6",
"@angular/material": "^6.3.0",

您对如何解决此问题有任何想法吗? 我阅读了其他解决方案,每个人都说明要添加正确的导入,所以我做到了,但问题仍然存在。

1 个答案:

答案 0 :(得分:0)

这是因为您可能没有在与组件相关的module.ts中导入CdkTreeModule和MatTreeModule。