3

I'm new to Angular. I recently deployed a sample webpage to Github Pages. I was successful at deploying but images that are visible on localhost are not showing up. Instead, I'm getting a 404 logged on the console.

This is the component containing the img :

home.component.html :

<div>
    <img src='assets/images/birthday.jpg' alt='Happy Birthday' width="385px"/>
</div>

My directory structure is :

   |src
   |--app
   |--assets
    |---images
     |----birthday.jpg

The directory structure in the dist folder is :

   |dist
   |--happy-birthday
    |--assets
     |---images
      |----birthday.jpg

I'm deploying using angular-cli-ghpages package. My Angular version is 10.0.14.

1
  • can you share your 404 error ? like it must have clearly defined the 'image path' that must be missing. Commented Aug 31, 2020 at 4:38

3 Answers 3

5

Try to use /assets/images/birthday.jpg.

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

Comments

0

Try explicitly giving a relative path (Path of the img relative to home.component.html) An example is given below, this may however change depending on your directory structure.

<div><img src='../assets/images/birthday.jpg' alt='Happy Birthday' width="385px"/></div>

Comments

0

I just tried without the leading slash and it worked: src='assets/images/birthday.jpg'.

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.