Images not loading from assets folder in Angular


Topic: Images not loading from assets folder in Angular

mani12 asked 6 years ago

path: 

in app.component.html.

assets and images folder location:   projectfolder\src\assets\images


Damian Gemza staff answered 6 years ago

Dear @mani12

You're using the wrong path to the images.

In the Angular project, you don't have to add the relative path from your file to image file.

Angular resolves this problem for you, and in a component, you have to only add a path to the assets folder, instead of ../../assets.

This code will work:

<img src="assets/img.jpg" alt="">

and this code will not work:

<img src="../../assets/img.jpg" alt="">

Best Regards,

Damian


hrt commented 2 years ago

using this how will angular know the precise image you intend to use?


Damian Gemza staff answered 6 years ago

Dear mani12,

Do you have img.jpg file in the src/assets folder? It's necessary to put there an image file.

Please take a look at this StackOverflow question.

Best Regards,

Damian


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: MDB5 2.3.0
  • Device: PC
  • Browser: chrome
  • OS: windows
  • Provided sample code: No
  • Provided link: No