sizz sizz - 1 year ago 87
HTML Question

Angular 2 app doesnt load JS scripts in html

I have some scripts in my html code in my angular 2 app and they do not load. When i check the console of the browser I do not see an attempt to even load the script? How can i load JS scripts in angular 2

div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="alert alert-dismissible fade in" role="alert">
<script type="text/javascript">
setInterval(function() {
}, 1000);
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span></button>
<span id="element">Loading...</span>

There is an example of one of the scripts.. This is being used in a component called home and i use the template home.html where this is located.

here is the home component code.

import {Component} from '@angular/core';

selector: 'home',
templateUrl: './home.html'
export class homecomponent { }

Answer Source

Angular just strips <script> tags from templates. You need other ways to load the script. For example using requirejs in your components code.

See also

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download