angularimageweb-hosting

Images are not displaying on server on angular18


I created an application on angular18. images are displaying on local server but when i deploy my project and upload it to my hosting then imgs are not dispalying in my project.Anyone faced this situation?

I tried many youtube videos but not finding solution. images are in public folder and in my project i placed it as <img src="img.png"> by using this path it imgs are showing in localhost but when i deploy my project and upload it to my hosting then imgs are not showing while other elements like text are showing.


Solution

  • When using Angular you should keep your static images in the ./assets folder and then refer to those images by using for example src="/assets/img.png". You should serve your website directly from the “browser” directory for this to work correctly.