ERROR: Can't bind to 'dataSource' since it isn't a known property of 'mat-tree'

本小妞迷上赌 提交于 2020-01-24 01:49:10

问题


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.

I added both

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

and

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

My current versions are:

"@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.


回答1:


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



来源:https://stackoverflow.com/questions/51027376/error-cant-bind-to-datasource-since-it-isnt-a-known-property-of-mat-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!