简体   繁体   English

Angular2图像相对于组件

[英]Angular2 image relative to component

How can I create a component that uses an resource that is in the same folder? 如何创建使用同一文件夹中的资源的组件? For instance, I want the background-image to be stored in component folder and then be able to use that component in a different module. 例如,我希望将背景图像存储在组件文件夹中,然后能够在不同的模块中使用该组件。

Thanks. 谢谢。

Any Resource like image\\font comes from path relative to your application URL, if you are configuring your server so that the component folder can be accessed and resources may be served from there, you may very well keep images in the component folder and use it, you just have to give the correct path traversing your project folders to your image. 任何像image \\ font这样的Resource都来自相对于应用程序URL的路径,如果您正在配置服务器以便可以访问组件文件夹并且可以从那里提供资源,那么您可以将图像保存在组件文件夹中并使用它,您只需要提供正确的路径遍历您的项目文件夹到您的图像。

Having said that is not a good practice, it may cause problems if you move your components, also its usually not a good idea to expose all the folders to the outside world. 说到这不是一个好习惯,如果你移动你的组件可能会导致问题,通常不是一个好主意将所有文件夹暴露给外面的世界。 What you may do is have a assets folder where you can keep images and make them available for use. 你可能会做的是有一个资产文件夹,你可以在其中保存图像并使其可供使用。

Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM