Angular 2 不重启不显示图像

Angular 2 not showing images without restarting

我正在使用 angular2 和 nodejs 上传图片,当节点在 assets 文件夹中上传文件时,我尝试使用 angular 显示它并得到一个错误:

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

但是当我的 angular 服务器重新启动时,图像就在那里。

如何在不重启的情况下显示图像?

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

问题是,当您 运行ning ng serve 在内存中触发时 webpack dev server - 不是您想要在服务器上 运行 的东西,也就是说仅供开发人员使用。这样,在您重新启动 ng serve 之前,您的 assets 文件夹不会发生任何变化,因为它是 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.

因此 assets 文件夹不是存储任何动态内容的最佳位置。