Question: How to add a js file for only one component?

is there something like : 

```
@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['../../assets/css/login.css'],
  "ScriptUrl" or something
})

```

Answer: 
I just used this function 

```
loadScript(src){
    var script = document.createElement("script");
    script.type = "text/javascript";
    document.getElementsByTagName("body")[0].appendChild(script);
    script.src = src;
  }

```

and called it in `ngOnInit()` by `this.loadScript('/js/file.js')`
I don't know if this is a good approach so let me know please.

**EDIt** 

or you can just `import(js file path)`in yout .ts file .
You couldn't add a script specific for a component in Angular JS2 like styles. But there is one feature in angular for Lazy load feature modules through routing. It will only loads the module and components files related to the particular feature module.

<https://angular-2-training-book.rangle.io/handout/modules/lazy-loading-module.html>