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

7
  • How are you using them inside the component exactly? Commented Dec 30, 2016 at 19:22
  • please take a look at this answer... Technically this option considered as security issue... Commented Dec 30, 2016 at 19:23
  • @PankajParkar yeah it shows the way but how to load this script file to browser inside the component function? do you think is fine simple http request ? or ? Commented Dec 30, 2016 at 19:29
  • @PankajParkar can you post your example as answer here Commented Dec 30, 2016 at 19:30
  • 1
    @PankajParkar you are lifesaver, let me accept your answer please eloborate it to make it clear for others who seeks same solution. thank you Commented Dec 30, 2016 at 19:55

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

1 Comment

how do I load it after other js files?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.