【问题标题】:ERROR: Can't bind to 'dataSource' since it isn't a known property of 'mat-tree'错误:无法绑定到“dataSource”,因为它不是“mat-tree”的已知属性
【发布时间】:2018-12-04 06:13:45
【问题描述】:

我添加了从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",

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

【问题讨论】:

  • 你在相关module.ts中导入了吗
  • 这通常发生在您尚未导入并添加所需模块时。您是否已将 MatTreeModule 添加到您的 app.ts 模块导入中?
  • @yer 我只在 main.ts 中添加。解决了添加到相关module.ts中非常感谢!
  • 请不要在标题中添加“SOLVED”并添加问题的答案。 meta.stackexchange.com/questions/116101/…

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-04-10
    • 2022-11-27
    • 2019-11-10
    • 1970-01-01
    • 2018-07-21
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多