Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Vanilla JavaScript library in Angular 6

I am getting following error when try to import existing Vanilla JavaScript library to Angular 6 component. Please suggest how to fix it.

Syntax to import the library, I have written

import * as ExistingLibrary from 'app/main/libs/ExistingLibrary.js';
ExistingLibrary.doJob is not a function

External JavaScript library - ExistingLibrary.js

var ExistingLibrary = new (function () {
    this.doJob = doJob;
    function doJob(template, options) {

    function f1(template, options) {}
    function f2(template, options) {}
});
like image 220
ANKIT Avatar asked Oct 18 '25 03:10

ANKIT


1 Answers

var ExistingLibrary = new (function () {
    this.doJob = doJob;
    function doJob(template, options) {

    function f1(template, options) {}
    function f2(template, options) {}
});

instead of this you need to export the functions like this:

export function doJob(template, options) { }
like image 132
MSzucs Avatar answered Oct 20 '25 18:10

MSzucs