0

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.

Makoto
  • 104,088
  • 27
  • 192
  • 230
Ferroz
  • 3
  • 1
  • 3
  • 1
    did you import in related module.ts – yer Jun 25 '18 at 15:50
  • it usually happens when you haven't imported and added the module required. have you added the MatTreeModule to your app.ts module imports ? – Gurvinder Guraya Jun 25 '18 at 15:55
  • @yer I added only in main.ts. solved adding it into the related module.ts Thank you very much! – Ferroz Jun 25 '18 at 15:56
  • 1
    Please refrain from adding "SOLVED" to the title and adding the answer to the question. https://meta.stackexchange.com/questions/116101/is-it-ok-to-add-solved-to-the-title-of-a-question –  Jun 25 '18 at 16:00

1 Answers1

4

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

yer
  • 1,454
  • 2
  • 16
  • 33