Javascript 如何将d3.js导入angular 2?
我使用的是angular 2的最终版本,没有angular cli和webpackJavascript 如何将d3.js导入angular 2?,javascript,d3.js,angular,npm,Javascript,D3.js,Angular,Npm,我使用的是angular 2的最终版本,没有angular cli和webpack import * as d3 from 'd3'; //ERROR: Cannot find module 'd3' 我安装了d3: npm安装d3——保存 有什么问题 system.config.js: /** * System configuration for Angular samples * Adjust as necessary for your application needs. */
import * as d3 from 'd3'; //ERROR: Cannot find module 'd3'
我安装了d3:
npm安装d3——保存
有什么问题
system.config.js:
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'map': 'npm:d3',
'rxjs': 'npm:rxjs',
'@ngrx': 'npm:@ngrx',
'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
d3: {
main: 'd3',
format: 'global'
},
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
main: '/bundles/Rx.min.js',
defaultExtension: 'js'
},
'@ngrx/core': {
main: 'bundles/core.min.umd.js',
format: 'cjs'
},
'@ngrx/store': {
main: 'bundles/store.min.umd.js',
format: 'cjs'
},
'@ngrx/effects': {
main: 'index.js',
format: 'cjs'
},
'@ngrx/store-devtools': {
main: 'bundles/store-devtools.min.umd.js',
format: 'cjs'
},
'@ngrx/store-log-monitor': {
main: 'bundles/store-log-monitor.min.umd.js',
format: 'cjs'
},
'@ngrx/router-store': {
main: 'bundles/router-store.min.umd.js',
format: 'cjs'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
typings.json:
{
"globalDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160831021119",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
}
}
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
您的代码中有一个JavaScript库(d3),您正试图将其导入到TypeScript代码中。TypeScript不知道该库的“形状”,您需要安装一个脚本才能使其工作。它没有任何功能,只是库的“形状”,以便TypeScript编译器知道它在使用什么。你能发布你的tsconfig.json吗?我在问题细节中添加了tsconfig.json。谢谢你的尝试,但是webstorm仍然找不到模块d3。没有任何意义。。。让我试试。试试这个:打字安装——全局——保存dt~D3工作!谢谢你有没有机会解释一下最后一个命令的作用?(+将最后一条命令添加到asnwer)
typings install --global --save dt~d3