Angular 2 - TypeError undefined不是Array包含

时间:2017-02-15 00:02:03

标签: javascript angular typescript charts tsconfig

我的Angular 2项目是使用angular-cli版本1.0.0-beta.30创建的。我正在使用ngx-charts版本4.1.2库。条形图组件工作正常,但是当我添加折线图时,运行应用程序时会引发TypeError异常。在Chrome版本38中运行时,错误是[line-chart.component.ts] [1]源文件的第240行中的“包含”功能。在Firefox中正确显示折线图

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

如何使数组包含我的应用程序已知的函数?

在我的tsconfig.json文件中,我有

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

我的package.json文件包含以下内容

{
  "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/common": "^2.4.5",
    "@angular/compiler": "^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/compiler-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"
  }
}

我的polyfills.ts文件包含

import 'core-js/es6/array';

我查看了ngx-charts演示和其他示例,但我无法弄清楚为什么我收到错误。

由于

1 个答案:

答案 0 :(得分:5)

我发现了问题。 polyfills.ts文件包含

// Authentication Routes...
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');

// Registration Routes...
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'Auth\ResetPasswordController@reset');

我需要添加

import 'core-js/es6/array';

到文件。

我认为这是因为公司电脑上安装了Chrome版本。它是版本38.此版本的developer.mozilla.org页面包含支持Chrome的状态为47的状态。