简体   繁体   中英

<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>

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM