0

I am trying to add the following javascript code through one angular controller

    const script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.type = 'text/javascript';
    script.async = false;

    script.setAttribute('src', './exampleJSCode.js');

The exampleJSCode file contains javascript functions but when I run this code I get lots of syntax errors (around 54) but the exampleJSCode file is formatted correctly.

How to escape that character which is causing syntax error?

4
  • What errors? Can you provide a snippet of the errors being generated in your IDE? Also, you should never modify the DOM from an Angular controller. Commented Sep 21, 2022 at 16:39
  • oh ohk, btw what are other ways, like i am in need of having the functions in the exampleJSCode file as a javascript functions in order to capture few events. Should I write them in angular and just pass the reference of that function in javascript function directly put in index.jsp file? Commented Sep 22, 2022 at 8:03
  • Execution pack-angular-js of goal net.alchim31.maven:yuicompressor-maven-plugin:1.5.1:compress failed: Compilation produced 54 syntax errors. Commented Sep 22, 2022 at 10:16
  • Per the angularjs docs, the only truly acceptable place to modify the DOM is from a directive. docs.angularjs.org/misc/faq#dom-manipulation Here is another SO article on the topic: stackoverflow.com/questions/37480150/… From your last comment it looks like your code has syntax errors which is why it isn't compiling. You need to view it from an IDE that highlights those for you or you need to find a way to have your pack-angular-js step output those syntax errors in the log and fix them. Commented Oct 5, 2022 at 21:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.