错误:无法绑定到“dataSource",因为它不是“mat-tree"的已知属性 [英] ERROR: Can't bind to 'dataSource' since it isn't a known property of 'mat-tree'

查看:20
本文介绍了错误:无法绑定到“dataSource",因为它不是“mat-tree"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了从 https://material.angular.io/components/tree 检索到的示例/overview(示例可见[https://stackblitz.com/angular/arbvompqpmg?file=main.ts]) 文档,但它抛出此错误:

I added the example retrieved from https://material.angular.io/components/tree/overview (The example can be seen[https://stackblitz.com/angular/arbvompqpmg?file=main.ts]) the documentation but it throw this error:

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",

你知道如何解决这个问题吗?我阅读了其他解决方案,每个人都解释了添加正确的导入,所以我做了但问题仍然存在.

Do you have any idea about how to solve this problem? I read other solutions and everybody explains to add correct imports, so I did but the problem still.

推荐答案

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

This is because you might not have imported CdkTreeModule and MatTreeModule in module.ts related to the component.

这篇关于错误:无法绑定到“dataSource",因为它不是“mat-tree"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆