I cant add my image to the web app, when i try to load a image from a url like
<img src="http://website/img.png">
works fine but when i try to open a image on my project doesn’t load
<img src="/assets/img.png">
i try with diferent images and change the path so many times to the public or other paths
2
Answers
Make sure you have
baseHref
set in your project.Then you create an assets folder and make sure you add it in the
angular.json
inside the assets array.Finally, you can import and use it.
After doing these changes, I had to restart my application for the changes to take effect.
Stackblitz Demo
I noticed that for new Angular 18 projects they’ve moved the default assets location in the repository from
/assets
to/public
and the output in the final build from/assets
to/
.So if you don’t want to change your
angular.json
you should put yourimg.png
in the/public
folder in your repository.In your template you should link to
/img.png
: