1

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.

Cosmin D
  • 639
  • 1
  • 11
  • 24

1 Answers1

0

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.

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!!

Madhu Ranjan
  • 17,334
  • 7
  • 60
  • 69
  • Yes, I do have an assets folder. I use the regular angular-cli project structure. I just want to export a component to be used as independent, and having its own background image. This is a third party component that I'll use in different projects. – Cosmin D Jan 23 '17 at 21:35
  • @csm86: you may also pass along an assets with the components, but you will have to copy them over to projects assets folder , at least now as including assets directly from imported library is not supported check this [SO question](http://stackoverflow.com/questions/41555624/how-to-include-assets-from-node-modules-in-angular-cli-project). Also check this [feature request](https://github.com/angular/angular-cli/issues/3555). – Madhu Ranjan Jan 23 '17 at 21:41