我正在尝试导入plotly.js
TypeScript。使用安装Plotly.js npm
。在我的TypeScript文件中
import 'plotly.js';
可以,但我在类似Plotly.<member>
以下代码时遇到错误:
error TS2304: Cannot find name 'Plotly'
当我尝试
import Plotly = require('plotly.js');
我越来越
error TS2307: Cannot find module 'plotly.js'.
最终得到:
declare function require(moduleName: string): any;
var Plotly = require('plotly.js/lib/index-basic.js');
(由于我只需要基本功能,请参考index-basic.js,将index.js用于完整的库。)
编辑(2018年2月):
现在首选的方法是将路径添加到tsconfig.json
文件中,如下所示:
"compilerOptions": {
"paths": {
"plotly.js": [
"../node_modules/plotly.js/lib/core.js"
]
}
}
然后.ts
像这样导入文件
import * as Plotly from 'plotly.js';
注意:在仅core.js
包含的路径(包含scatter
图形)中,您可以根据需要导入其他图形。
(我在Angular CLI中使用它-Angular 5.2和Typesript 2.7.1)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句