Anush Chakhoyan Anush Chakhoyan - 5 months ago 43
Node.js Question

Angular 2 not showing images without restarting

I'm uploading an image using angular2 and nodejs, when node uploads file in assets folder, I try to show it using angular and get an error:

GET http://localhost:4200/assets/img/3.jpg 404 (Not Found)

But when my angular server restarts the image is there.

What can I do to show an image without restarting?

Answer Source

As you reply to my comment - you are using ng serve.

The thing is, when you are running ng serve that triggered in memory webpack dev server - not a thing you want to run on your server, that is for dev only. This way, until you restarted ng serve, you wont get any changes happend in your assets folder as it is default folder for your static assets configured in .angular-cli.json:

You use the assets array in .angular-cli.json to list files or folders you want to copy as-is when building your project.

So assets folder is not the best place to store any dynamic content.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download