无法访问像'd3.svg(),d3.scale()`和d3js中的一些其他属性与angular2

时间:2017-09-01 12:29:00

标签: javascript angular d3.js

我正在尝试在angular2中使用d3.js. 我使用以下命令在Angular2中安装d3

npm install --save d3
install --save-dev @types/d3

我的 package.json 看起来像

{
  "name": "my-app",
  "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": {
    "@angular/animations": "^4.0.0",
    "@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/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "core-js": "^2.4.1",
    "d3": "^4.10.0",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.2.1",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/d3": "^4.10.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@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"
  }
}

我将路径添加到.angular-cli.json

我无法访问的一些属性,如d3.svg(), d3.scale()和其他一些

它返回错误。

可能是什么原因?

1 个答案:

答案 0 :(得分:0)

您可以从d3导入特定方法,与r​​xjs运算符相同。

import { scaleLinear } from 'd3-scale';

您可以使用不带d3名称空间的方法:

var x = scaleLinear();

或者,您可以导入所有

import * as d3 from "d3";

var x = d3.scaleLinear();

请注意,d3.v4中没有缩放