-1

I am trying to load a java script file in to a component. If the file is copied outside the 'src' folder it is working fine, but inside 'src' folder it is getting 404 error. I tried with different scenarios but issue not resolved.
enter image description here

404 error enter image description here

Thanks
Vimal

Vimal
  • 2,767
  • 3
  • 19
  • 24

2 Answers2

0

When you serve angular application it starts the server at port 4200 with directory PROJECT_FOLDER/src that is when you load the script in component it already in the src folder so just use app/shared/... instead of src/app/shared/....

Sunil Kashyap
  • 2,946
  • 2
  • 15
  • 31
0

I think Angular will consider those as static files, meaning that they won't load on compile time, but rather at runtime, and at runtime there will be on /src but instead only assets (or what you ask Angular to copy over from src.

You have 2 options here:

1- Moving your static files into asstes and then you can reference them as /assets/payment/js/init-payment.js.

2- Ask Angular to copy certain directory from src into build directory when compiling. and that's done in angular.json file inside the assets array.
For more details see this answer here:

Whats the default path for static files in Angular2?

Nadhir Falta
  • 5,047
  • 2
  • 21
  • 43