问题
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>
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:
import {Component,ViewEncapsulation} from '@angular/core';
@Component({
selector:'app-slider',
templateUrl:'../templates/slider.component.html'
})
export class SliderComponent{
constructor(){}
}
slider.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
回答1:
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
System.import('filepath.js'); //or below one
require('filepath.js');
来源:https://stackoverflow.com/questions/41401141/cant-add-script-file-to-components-html