1

I need help. I'm working on an Angular project. I'm making some API calls (GET/PUT) to a remote server. To save time and prformance of my application I thought let's keep it in my local itself. So, I downloaded the JS file and kept it in assets folder.

Previously the code was:

private loadMySisenseJs(): Promise<any> {
    ...
    // load required js
    this.sisenseJsLoadPromise = new Promise((resolve, reject) => {
        const sisenseJsSrc = 'https://sisense-dev.dummy.com/js/sisense.js'; // FROM SERVER
        ...    
        });
        return this.sisenseJsLoadPromise;
    }
}

Now the code is:

private loadMySisenseJs(): Promise<any> {
    ...
    // load required js
    this.sisenseJsLoadPromise = new Promise((resolve, reject) => {
        const sisenseJsSrc = '../../../assets/sisense.js'; // FROM LOCAL
        ...    
        });
        return this.sisenseJsLoadPromise;
    }
}

But I'm still getting: enter image description here

I tried these things also:

1. index.html

<script type="text/javascript" src="path-to-javascript-file.js"></script>

angular.json

"scripts": [
        ...
        "(local path to js file)/sisense.js"
    ]

But still the same problem. Please help me.

Tanzeel
  • 4,174
  • 13
  • 57
  • 110

1 Answers1

0

You need to serve your local file using some web server. Or a easier way would be to just import local file as module.

import "path/to/localfile.js";

then you can directly use methods/variables from that file.

Amit
  • 3,662
  • 2
  • 26
  • 34