Reputation: 2444
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
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