无法将脚本文件添加到组件 html [英] cant add script file to components html
问题描述
我在 index.html(root) 中有一个脚本文件引用;index.html:
I have had a script file reference in index.html(root); index.html:
<script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>
这里不需要sliderfunctions.js,它包含了一些关于slider的特定功能,所以我把它放到slider.component.html文件中,但你猜它没有像我预期的那样工作,实际上它从未加载到浏览器中..
no need sliderfunctions.js here, it contains some specific functions about slider so I carry it to slider.component.html file but as you guess it doesnt work as I expected actually it never loaded to browser..
slider.component.ts:
slider.component.ts:
import {Component,ViewEncapsulation} from '@angular/core';
@Component({
selector:'app-slider',
templateUrl:'../templates/slider.component.html'
})
export class SliderComponent{
constructor(){}
}
slider.component.html:
slider.component.html:
<script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>
(我携带了其中的 3 个,因为脚本的顺序很重要)所以我想得到一个特定的点,我已经在网上搜索但无法弄清楚如何在组件模板中添加脚本文件
(I carried 3 of them because order of scripts is important)so I want to get a specific point that I already make search on net but cant figure out how to add script file within component templates
推荐答案
您的想法被视为安全威胁.您可以按照 这个答案
The way you're thinking of is considered as security threat. You could either follow this answer
或
您可以从 component.ts
文件中引用脚本文件,只需执行 System.import
/require
You can refer script file from the component.ts
file, just by doing System.import
/require
System.import('filepath.js'); //or below one
require('filepath.js');
这篇关于无法将脚本文件添加到组件 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!