0

To load JavaScript to angular application create a function like below and invoke this function any one of component life cycle as based on require where user wants to invoke

public loadScript(url) {
        console.log('preparing to load...')
        let node = document.createElement('script');
        node.src = url;
        node.type = 'text/javascript';
        document.getElementsByTagName('head')[0].appendChild(node);
    }

To invoke as 
ngOnInit() {
        this.loadScript("/assests/test.js")

    }
  • Nope. It's a local function, not a native JS function. If you want to make a global function, use `window`. –  Jul 11 '17 at 09:01

1 Answers1

0

you have to use Promise in this case, please refer below link, I have already given answer on it:

https://stackoverflow.com/a/44276683/6606630