7

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

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96

1 Answers1

5

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');
Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299