【问题标题】:Import external javascript to Ionic将外部 javascript 导入 Ionic
【发布时间】:2017-12-02 10:17:14
【问题描述】:

我在尝试将 javascript 库导入到我的 Ionic 应用程序时遇到了一些问题,特别是将此图表导入到我的 ionic 项目中

https://github.com/rendro/easy-pie-chart. 

首先我安装最新的 ionic,然后转到

/src/

打开assets文件夹,创建一个

/js/

assets 里面的文件夹 复制这个 js 文件夹里面的 .js 去

/src/index.html

添加路径<script src="assets/js/N.js"> 转到 typescript 文件并声明 var N;

还有一个类似这个视频的方式:https://www.youtube.com/watch?v=xWIzZ8wBqk0

但是他们两个都没有工作。你还有什么想法吗?谢谢。

【问题讨论】:

  • 一般你需要一个typescript类型声明文件来导入一个js库。这个好像没有。此外,它看起来没有任何最近的更新。建议您寻找替代解决方案
  • 是的,我已经声明了这样的变量:declar var easyPieChart:any;

标签: ionic-framework charts ionic2 ionic3 data-visualization


【解决方案1】:

你需要改变你的 tsconfig.json “声明”:真的,像这样

{
  "compilerOptions": {
  "allowSyntheticDefaultImports": true,
  "declaration": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": ["dom", "es2015"],
  "module": "es2015",
  "moduleResolution": "node",
  "sourceMap": true,
  "target": "es5"
 },
 "include": ["src/**/*.ts"],
 "exclude": ["node_modules", "src/**/*.spec.ts", "src/**/__tests__/*.ts"],
 "compileOnSave": false,
 "atom": {
   "rewriteTsconfig": false
 }
}

你需要在你的项目中创建一个文件夹和一个像'typings/index.d.ts'这样的文件

see this image

希望你能理解我蹩脚的英语

【讨论】:

  • 我们需要将文件夹命名为“types”还是“typings”?在文本中你说打字,但在图片中它说“类型”
猜你喜欢
  • 2018-07-11
  • 1970-01-01
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 2018-04-06
  • 2017-02-15
  • 2012-03-23
相关资源
最近更新 更多