Is it mandatory to keep images in assets folder in Angular 2?

試著忘記壹切 提交于 2019-12-23 05:34:10

问题


Images are kept in "assets" directory as its public but can it be kept in respective components so HTML files can easily access


回答1:


It is not required to put images in assets project.

Asset folder is preconfigured. When you run build command then all the things in asset folder will copied to output folder(dist) automatically for publish. So no need to copy manually.

You can also configured different folder as a asset. see in below code sample.

  "assets": [
    "assets",
    "xyz",
    "favicon.ico"
  ],



回答2:


Assets folder is used in angular for maintaining file which doesn't have to be modified while compiling. You can't maintain any files like Images, json or any other file types in a component folder(folders are only for development purpose only) because it will be not recognized while compiling.

If you are in any component always set image path like this. Always maintain assets as a starting folder

"assets/pic.img"

Not like this and it won't be recognized

"./../assets/pic.img"


来源:https://stackoverflow.com/questions/46149846/is-it-mandatory-to-keep-images-in-assets-folder-in-angular-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!