esseara esseara - 3 years ago 119
Javascript Question

Angular 4 index.html won't load any script

This is frustrating, I'm trying to load a simple script inside my

but I get 404.


<meta charset="utf-8">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="./app/scripts/angular-cookies.js"></script>

This is my project structure

enter image description here

This is the error I get - 404

enter image description here

The file is there and it's not empty. I tried also:

<script type="text/javascript" src="../app/scripts/angular-cookies.js">


<script type="text/javascript" src="app/scripts/angular-cookies.js">


<script type="text/javascript" src="/app/scripts/angular-cookies.js">

Any help would be appreciated, thanks!

sTx sTx
Answer Source

As I've mentioned in comment, any external resource should be placed in assets folder and for your case referenced like <script type="text/javascript" src="assets/scripts/angular-cookies.js"> considering assets contains a folder named scripts which contains your angular-cookies.js file. After building the code the resulted www folder will be like:

  • assets -> which contains the external files
  • build -> which contains your ts files transpiled into js files
  • index.html
  • other files
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download