nifCody nifCody - 9 months ago 42
Javascript Question

<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

and put an alert box.

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

How do i implement
on angular 2 applications.

$(document).ready(function() {
alert("Hello from JS");

Answer Source

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

You can use

class MyComponent {
  ngAfterContentInit() {

or add JavaScript to your TypeScript by other means like require