angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.37k stars 6.75k forks source link

Unable to use Mat-Tree in angular 4 #12354

Closed prashantpimpale93 closed 6 years ago

prashantpimpale93 commented 6 years ago

Bug, feature request, or proposal:

I am trying to integrate angular material Tree module in my project. When I copied the related code from Document in my project it's throwing an error.

What is the expected behavior?

It should work after npm install

What is the current behavior?

Error:

1) Argument of type '(node: TodoItemNode) => TodoItemNode[]' is not assignable to parameter of type '(node: TodoItemNode) => Observable<TodoItemNode[]>'. Type 'TodoItemNode[]' is not assignable to type 'Observable<TodoItemNode[]>'. Property '_isScalar' is missing in type 'TodoItemNode[]'.

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.
StackBlitz starter: https://goo.gl/wwnhMV

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

"typescript": "~2.3.3"

"rxjs": "^5.5.11"

Is there anything else we should know?

Package.Json:

{
  "name": "kalpavriksha-angular-v4",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.1",
    "@agm/snazzy-info-window": "^1.0.0-beta.1",
    "@angular/animations": "^4.4.6",
    "@angular/cdk": "^6.0.0-beta.4",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^6.0.0-beta.4",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "@swimlane/ngx-charts": "^6.1.0",
    "@types/filesaver": "0.0.30",
    "angular-chat": "^1.0.9",
    "angular-datatables": "^4.2.0",
    "angular-file-picker": "^1.2.0",
    "angular-file-saver": "^1.1.3",
    "angular-material": "^1.1.5",
    "angularfire2": "5.0.0-rc.3",
    "angularjs-bootstrap-datetimepicker": "^1.1.4",
    "chart.js": "^2.7.2",
    "chart.piecelabel.js": "^0.11.0",
    "cloudboost": "^2.0.264",
    "core-js": "^2.4.1",
    "d3": "^4.11.0",
    "datatables.net": "^1.10.16",
    "datatables.net-buttons": "^1.4.2",
    "datatables.net-buttons-dt": "^1.4.2",
    "datatables.net-dt": "^1.10.16",
    "datatables.net-select": "^1.2.3",
    "datatables.net-select-dt": "^1.2.3",
    "file-saver": "^1.3.3",
    "firebase": "4.6.0",
    "hammerjs": "^2.0.8",
    "material-design-icons": "^3.0.1",
    "md-date-picker": "^0.1.0",
    "ng-chat": "^1.0.12",
    "ng-snotify": "^4.0.0",
    "ng2-charts": "^1.6.0",
    "ng2-search-filter": "^0.3.1",
    "ng4-loading-spinner": "^1.0.27",
    "ngx-cookie-service": "^1.0.9",
    "ngx-inactivity": "^1.0.1",
    "ngx-loading": "^1.0.7",
    "ngx-pagination": "^3.1.0",
    "ngx-progress-bar": "0.0.10",
    "rxjs": "^5.5.11",
    "snazzy-info-window": "^1.1.0",
    "time-ago-pipe": "^1.3.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.4.1",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/datatables.net": "^1.10.6",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.12",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

Imports in Component:

import {SelectionModel} from '@angular/cdk/collections';
import {FlatTreeControl} from '@angular/cdk/tree';
import { Injectable} from '@angular/core';
import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree';
import {BehaviorSubject} from 'rxjs';
import { of } from 'rxjs/observable/of';
djleonskennedy commented 6 years ago

@prashantpimpale93 minimum ng version for mat-tree is 6+

prashantpimpale93 commented 6 years ago

Ok, then is it mandatory (As I don't know how much it will impact) to upgrade Version 4 to 6?

prashantpimpale93 commented 6 years ago

@djleonskennedy Yes I tried update but getting error :

Argument of type '(node: TodoItemNode) => TodoItemNode[]' is not assignable to parameter of type '(node: TodoItemNode) => Observable<TodoItemNode[]>'.
  Type 'TodoItemNode[]' is not assignable to type 'Observable<TodoItemNode[]>'.
    Property '_isScalar' is missing in type 'TodoItemNode[]'.
jelbourn commented 6 years ago

Each major version of Angular Material requires at least the same major version of Angular. E.g., Angular Material v6 requires Angular v6.

MRebati commented 6 years ago

I also have the same issue. the minimum requirements are met.

my packages:

"dependencies": {
    "@angular/cdk": "^6.3.3",
    "@angular/material": "^6.3.3",
    "angular2-pubsub": "^4.0.3",
    "hammerjs": "^2.0.8"
  },
  "devDependencies": {

    "@angular-devkit/build-angular": "0.6.3",
    "@angular/animations": "^6.0.5",
    "@angular/cli": "6.0.5",
    "@angular/common": "6.0.5",
    "@angular/compiler": "6.0.5",
    "@angular/compiler-cli": "6.0.5",
    "@angular/core": "6.0.5",
    "@angular/forms": "6.0.5",
    "@angular/http": "6.0.5",
    "@angular/language-service": "6.0.5",
    "@angular/platform-browser": "6.0.5",
    "@angular/platform-browser-dynamic": "6.0.5",
    "@angular/router": "6.0.5",
    "@ngx-translate/core": "10.0.1",
    "@ngx-translate/http-loader": "3.0.1",
    "@types/jasmine": "2.8.7",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "8.9.4",
    "codelyzer": "4.2.1",
    "core-js": "2.5.6",
    "electron": "2.0.3",
    "electron-builder": "20.14.7",
    "electron-reload": "1.2.2",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "^2.0.4",
    "karma-chrome-launcher": "2.2.0",
    "karma-coverage-istanbul-reporter": "2.0.0",
    "karma-jasmine": "1.1.2",
    "karma-jasmine-html-reporter": "1.1.0",
    "npm-run-all": "4.1.3",
    "npx": "10.2.0",
    "protractor": "5.3.2",
    "rxjs": "6.1.0",
    "ts-node": "6.0.3",
    "tslint": "5.10.0",
    "typescript": "2.7.2",
    "wait-on": "2.1.0",
    "webdriver-manager": "12.0.6",
    "zone.js": "0.8.26"
  }

I have all packages in 6.* version.

MRebati commented 6 years ago

I found a workaround for this:

if you still getting the same error in the console then do this:

private getChildren(node: FileNode): Observable<FileNode[]> {
    const observable = of(node.children);
    return observable;
}
prashantpimpale93 commented 6 years ago

@MRebati Thanks! will try and inform the same

praveenhariyala commented 6 years ago

i am also facing same issue

Argument of type '(node: TodoItemNode) => TodoItemNode[]' is not assignable to parameter of type '(node: TodoItemNode) => Observable<TodoItemNode[]>'. Type 'TodoItemNode[]' is not assignable to type 'Observable<TodoItemNode[]>'. Property '_isScalar' is missing in type 'TodoItemNode[]'.

hear i am using angular6 amgular material 6 and "rxjs" 6 as well

please have look my packege.json

{ "name": "my-app", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "^6.0.7", "@angular/cdk": "^6.3.3", "@angular/common": "^6.0.7", "@angular/compiler": "^6.0.7", "@angular/core": "^6.0.7", "@angular/forms": "^6.0.7", "@angular/http": "^6.0.7", "@angular/material": "^6.3.3", "@angular/platform-browser": "^6.0.7", "@angular/platform-browser-dynamic": "^6.0.7", "@angular/router": "^6.0.7", "@ng-bootstrap/ng-bootstrap": "^2.2.1", "@ngrx/core": "^1.2.0", "@ngrx/effects": "^6.1.0", "@ngrx/entity": "^6.1.0", "@ngrx/router-store": "^6.1.0", "@ngrx/store": "^6.1.0", "@ngrx/store-devtools": "^6.1.0", "@swimlane/ngx-datatable": "^13.1.0", "amexio-ng-extensions": "^5.0.5", "angular-font-awesome": "^3.1.2", "angular2-fontawesome": "^5.2.1", "bootstrap": "^4.1.3", "chart.js": "^2.7.2", "core-js": "^2.5.4", "echarts": "^4.1.0", "font-awesome": "^4.7.0", "jquery": "^3.3.1", "ng2-charts": "^1.6.0", "ng2-table": "^1.3.2", "ng2-tooltip": "0.0.7", "ng2-tree": "^2.0.0-alpha.8", "ngx-echarts": "^4.0.0", "ngx-treeview": "^6.0.0", "rxjs": "^6.3.1", "rxjs-compat": "^6.3.1", "tether": "^1.4.4", "zone.js": "^0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.6.0", "@angular-devkit/build-ng-packagr": "~0.6.0", "@angular/cli": "6.0.8", "@angular/compiler-cli": "^6.0.7", "@angular/language-service": "^6.0.7", "@ngrx/schematics": "^6.1.0", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "~4.2.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~1.7.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~1.4.2", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "ng-packagr": "^3.0.0-rc.2", "protractor": "~5.3.0", "ts-node": "~5.0.1", "tsickle": ">=0.25.5", "tslib": "^1.7.1", "tslint": "~5.9.1", "typescript": "~2.7.2" } }

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.