Lukasz
Lukasz

Reputation: 711

importing javaScript to Angular2

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;

however I cannot import it into my component with

import hlghtta from "hlghtta";

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

Upvotes: 0

Views: 52

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 19622

Try this

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);   
    }
}

Upvotes: 1

Related Questions