Can not add script file to html components

I had a link to the script file 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 the slider, so I transfer it to the slider.component.html file, but, as you might imagine, it does not work, since I expected that it never loads into the 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 took 3 of them because the order of the scripts is important), so I want to get a specific point that I am already doing a network search, but I can’t figure out how to add the script file to the component templates

+5
source share
1 answer

What you think is considered a security risk. You can either execute this answer

OR

You can send the script file from component.ts by simply doing System.import / require

 System.import('filepath.js'); //or below one require('filepath.js'); 
+3
source

Source: https://habr.com/ru/post/1262096/


All Articles