Angular 2应用不会加载html格式的JS脚本

Angular 2 app doesnt load JS scripts in html

本文关键字:格式 JS 脚本 html 加载 应用 Angular      更新时间:2023-09-26

我有一些脚本在我的html代码在我的angular 2应用程序,他们不加载。当我检查浏览器控制台时,我甚至没有看到加载脚本的尝试?如何在angular 2中加载JS脚本

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() {
                                $('#element').load('/Resources/speedtest.txt');
                            }, 1000);
                        </script>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span></button>
                        <span id="element">Loading...</span>
                    </div>
                </div>

有一个脚本的例子…这是在一个名为home的组件中使用的,我使用的模板是home.html。

这里是home组件代码。

import {Component} from '@angular/core';
@Component({
    selector: 'home',
    templateUrl: './home.html'
})
export class homecomponent { }

Angular只是从模板中剥离<script>标签。您需要其他方法来加载脚本。例如,在你的组件代码中使用需求。

参见https://github.com/angular/angular/pull/12172