nifCody
nifCody

Reputation: 2444

<script> tag elements are not working on Angular 2 CLI created application

I have create an application using angular cli. My application is the angular 2 application. I would like to run a <script> and put an alert box.

I have try to load the <script> on hello.component.html but it does not work. And also I try put the <script></script> inside the index.html but it also fails.

How do i implement <script></script> on angular 2 applications.

<script>
  $(document).ready(function() {
    alert("Hello from JS");
  });
</script>

Upvotes: 1

Views: 1807

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657148

<script> tags in Angular2 component templates are just silently stripped.

You can use

class MyComponent {
  ngAfterContentInit() {
    alert("...");
  }

or add JavaScript to your TypeScript by other means like require

Upvotes: 2

Related Questions