【发布时间】:2018-05-29 08:41:32
【问题描述】:
我刚刚加入了一个 Angular 5 项目(技术新手)。 我需要使用外部 javascript 文件中的函数。
我在这里找到了一些信息:How to include external js file in Angular 4 and call function from angular to js
但它不起作用。我做错了什么?
我在项目中添加了我的 js 文件,并在 .angular-cli.json 中声明了它:
"scripts": [ "./assets/js/kia.js" ],然后我在 typings.d.ts 中声明了它:
declare var kia: any;最后我尝试将它导入到我使用的文件中 detail.component.ts :
import * as variable from 'kia';
我遇到了错误:错误 TS2307: 找不到模块“起亚”。
有人知道如何解决这个问题吗?
【问题讨论】:
-
在我的 component.ts 中,我将导入更改为:
import * as kia from '../../assets/js/kia.js';并在 tsconfig.json 中添加了"allowJs": true,编译器选项。现在我有错误:src/typings.d.ts(3,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'kia' must be of type '{ COMMANDE_INIT: string; COMMANDE_EXECUTER_CALLBACK: string; ACQUITTER_: string; m_NomFenetre: an...', but here has type 'any'.
标签: javascript angular import angular5