Im looking for a way to access a variable from external js file which i included in assets/data folder
below is what i tried
placed test.js
None of above solutions worked for me, In first solution js file loads at the time of application loading that's not perfect solution when you have bulk js file.
I was looking for dynamic solution to load the external library and there is library for loading asynchronous JavaScript files. https://www.npmjs.com/package/scriptjs
Install the package:
npm i scriptjs
Then use it anywhere like below:
import { get } from 'scriptjs';
ngOnInit() {
get("assets/js/searchEmp.js", () => {
getSerchInspContext = this;
loadSearchEmp();
});}
OR
You can simply use the jquery method to append or remove the script tag in your header.
To add .js file, call below line under ngOnInit():
$('head').append('');
Remove .js file:
document.querySelector('script[src="assets/js/search.js"]').remove();