-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

2 Answers 2

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/....

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

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.