typescript 无法将脚本文件添加到组件 html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41401141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cant add script file to components html
提问by TyForHelpDude
I have had a script file reference in index.html(root); index.html:
我在 index.html(root) 中有一个脚本文件参考;索引.html:
<script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>
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..
这里不需要sliderfunctions.js,它包含一些关于slider的特定功能,所以我把它带到slider.component.html文件中,但正如你猜的那样,它并没有像我预期的那样工作,实际上它从未加载到浏览器中。
slider.component.ts:
滑块.component.ts:
import {Component,ViewEncapsulation} from '@angular/core';
@Component({
selector:'app-slider',
templateUrl:'../templates/slider.component.html'
})
export class SliderComponent{
constructor(){}
}
slider.component.html:
滑块.component.html:
<script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>
(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
(我携带了其中的 3 个,因为脚本的顺序很重要)所以我想得到一个特定的点,我已经在网上进行了搜索,但无法弄清楚如何在组件模板中添加脚本文件
采纳答案by Pankaj Parkar
The way you're thinking of is considered as security threat. You could either follow this answer
您所考虑的方式被视为安全威胁。你可以按照这个答案
OR
或者
You can refer script file from the component.ts
file, just by doing System.import
/require
您可以从component.ts
文件中引用脚本文件,只需执行System.import
/require
System.import('filepath.js'); //or below one
require('filepath.js');