2

I've noticed that scripts written in html templates are ignored in Angular (still learning it), but I want to run them sometimes despite the potential risks as stated by Angular. How could I do this?

Example:

@Component({
    templateUrl: '/html/pagex.html'
})

pagex.html:
<script>
    $(function(){alert("hi")})
</script>

Considering that some of my tags would generate JS code on runtime dynamically, modifying the script tag is not an option here.

12
  • And I assume it's not possible for you to simply execute the code within your component.ts file? Commented Dec 6, 2017 at 20:29
  • @user184994: exactly, since I have purchased my UI components and I can't modify any part of it. Commented Dec 6, 2017 at 20:30
  • 1
    Extend the component and then add the function in the child component? Commented Dec 6, 2017 at 20:46
  • @DrewRochon: I need to handle it only and only in the html file, without adding any function to the component. In other words, I want Angular to STOP removing the script tag. Commented Dec 6, 2017 at 20:48
  • 1
    can you show your full template code with purchased ui item? I bet there is another way to solve your problem. Commented Dec 6, 2017 at 21:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.