将JavaScript导入Angular2 [英] importing javaScript to Angular2

查看:70
本文介绍了将JavaScript导入Angular2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有angular2应用程序,我想在其中使用来自外部JS文件的hlghtta myJSfile.js

I have angular2 application, I want to use in it hlghtta from an external JS file myJSfile.js

var hlghtta = function (b, t, re, c) {
    "use strict";
     .......some functions here
};
module.exports = hlghtta;

但是我无法使用

import hlghtta from "hlghtta";

我已经将 myJSfile.js 添加到.angular-cli.json你能帮帮我吗?可能很简单.

I already added myJSfile.js to .angular-cli.json could you please help guys? might be something simple.

推荐答案

尝试一下

理想情况下,您应该输入文字,但是如果没有,您可以使用这种方式.您还可以查看链接了解更多信息

Ideally you should have typings but if not you can use this way . You can also check this link on more info

declare var hlghtta: any;

import '../../../../hlghtta.js';
export class Component {
    ngOnInit() {
        new hlghtta(params);   
    }
}

这篇关于将JavaScript导入Angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆