144
rated 0 times
[
148]
[
4]
/ answers: 1 / hits: 19608
/ 6 Years ago, fri, october 12, 2018, 12:00:00
I am trying to use a js file into my angular 6 application. Steps I followed are as follows:
1. Created testfile.js
file:
var testa = function () {
function testMethod() {
console.log('hello');
}
}
var testmodule = new testa();
module.exports = testmodule;
2. In angular.cli.json
. For testing purpose tesfile.js is at the same location as angular.cli.json
is:
scripts: [
testfile.js
],
3. In typings.d.ts file, declared it:
declare var testmodule: any;
4. In ts file, tried to use it as:
public ngOnInit() {
testmodule.testMethod()
}
But when angular component is used, warning in console is:
Uncaught ReferenceError: testmodule is not defined
I tried another alternative, like importing js file inside .ts file as:
import * as mymodule '../../testfile.js'
allowJs: true
but this is also not identifying testmodule or testfile.
What wrong am I doing here?
More From » angular