0

I am using Angular 5 in an attempt to display an image that I have sat in a file 2 directories up from where I have the HTML, however I simply get the blank image box and an error in the console of:

GET http://localhost:4200/logo.jpg 404 (Not Found)

I am attempting to output via the code:

<img src="../../logo.jpg">

I have tested by placing a placeholder.it image within the src which worked perfectly... For some reason this will not?

1
  • 1
    You have to copy the image using .angular-cli.json. Your image is missing from the output folder. Commented Feb 1, 2018 at 16:02

1 Answer 1

5

If you are using @angular/cli you'd need to place your images under /src/assets/ in line with the .angular-cli.json asset configuration. You can then just use the image directly such as:

<img src="assets/pa-logo.jpg">

You can create additional folders under "assets" property in .angular-cli.json for additional control/organization as necessary:

  "assets": [
    "assets",
    "foobar",
    "favicon.ico"
  ],

Usage after you placed pa-logo.jpg in the this hypothetical foobar folder:

<img src="foobar/pa-logo.jpg">

Hopefully that helps!

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

2 Comments

Aha! What a strange thing to happen. Why wouldn't you be able to use an image based anywhere? :-(
Effectively behind the scenes webpack is resolving paths as part of build process. You could alternatively use path relative to the root I believe.

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.