javascript - Angular 2 - TypeError undefined is not a function for Array includes - Stack Overflow

My Angular 2 project was created with angular-cli version 1.0.0-beta.30.I am using the ngx-charts ver

My Angular 2 project was created with angular-cli version 1.0.0-beta.30. I am using the ngx-charts version 4.1.2 library. The bar chart ponent is working fine but when I add a line chart, a TypeError exception is thrown when I run the application. The error is the "includes" function in line 240 of [line-chartponent.ts][1] source file when running in Chrome version 38. The line chart appears correctly in Firefox

if (!values.includes(d.name)) {
    values.push(d.name);
}

How do I make the array include function known to my application?

In my tsconfig.json file I have

"lib": ["es6", "dom"],

My package.json file contains the following

{
  "name": "dashboards",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/mon": "^2.4.5",
    "@angular/piler": "^2.4.5",
    "@angular/core": "^2.4.5",
    "@angular/forms": "^2.4.5",
    "@angular/http": "^2.4.5",
    "@angular/platform-browser": "^2.4.5",
    "@angular/platform-browser-dynamic": "^2.4.5",
    "@angular/router": "^3.4.1",
    "@swimlane/ngx-charts": "^4.1.2",
    "core-js": "^2.4.1",
    "d3": "^4.4.0",
    "rxjs": "^5.0.3",
    "ts-helpers": "^1.1.2",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.30",
    "@angular/piler-cli": "^2.4.5",
    "@types/d3": "^4.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.7.0",
    "karma": "1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-remap-istanbul": "^0.4.0",
    "protractor": "~4.0.14",
    "ts-node": "1.7.2",
    "tslint": "^4.3.0",
    "typescript": "~2.0.10"
  }
}

My polyfills.ts file contains

import 'core-js/es6/array';

I've looked through the ngx-charts demo and other examples but I can't figure out why I am receiving the error.

Thanks

My Angular 2 project was created with angular-cli version 1.0.0-beta.30. I am using the ngx-charts version 4.1.2 library. The bar chart ponent is working fine but when I add a line chart, a TypeError exception is thrown when I run the application. The error is the "includes" function in line 240 of [line-chart.ponent.ts][1] source file when running in Chrome version 38. The line chart appears correctly in Firefox

if (!values.includes(d.name)) {
    values.push(d.name);
}

How do I make the array include function known to my application?

In my tsconfig.json file I have

"lib": ["es6", "dom"],

My package.json file contains the following

{
  "name": "dashboards",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/mon": "^2.4.5",
    "@angular/piler": "^2.4.5",
    "@angular/core": "^2.4.5",
    "@angular/forms": "^2.4.5",
    "@angular/http": "^2.4.5",
    "@angular/platform-browser": "^2.4.5",
    "@angular/platform-browser-dynamic": "^2.4.5",
    "@angular/router": "^3.4.1",
    "@swimlane/ngx-charts": "^4.1.2",
    "core-js": "^2.4.1",
    "d3": "^4.4.0",
    "rxjs": "^5.0.3",
    "ts-helpers": "^1.1.2",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.30",
    "@angular/piler-cli": "^2.4.5",
    "@types/d3": "^4.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.7.0",
    "karma": "1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-remap-istanbul": "^0.4.0",
    "protractor": "~4.0.14",
    "ts-node": "1.7.2",
    "tslint": "^4.3.0",
    "typescript": "~2.0.10"
  }
}

My polyfills.ts file contains

import 'core-js/es6/array';

I've looked through the ngx-charts demo and other examples but I can't figure out why I am receiving the error.

Thanks

Share Improve this question edited Feb 20, 2017 at 5:45 Langfo asked Feb 15, 2017 at 0:02 LangfoLangfo 4305 silver badges17 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

I found the problem. The polyfills.ts file contained

import 'core-js/es6/array';

I needed to add

import 'core-js/es7/array';

to the file.

I'm thinking this is due to the version of Chrome installed on my corporate PC. It is version 38. This developer.mozilla page for Array.includes states that support for Chrome is in version 47.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745171301a4614941.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信