1

I am looking for a way to put images in the Angular Component Library. I mean img[src]. As for background-image, the library finds images from the assets folder, but if I try to attach images to img[src], it doesn't work. I also tried different src paths, absolute and relative. I know the base64 way, but is there anything else? I'm using Angular v12 and my ng-package.json looks like below:

  "assets": [
    "/assets/**/*",
    "/styles.scss",
    "/styles/**/*.scss"
  ]

In angular project below code works just fine:

<img src="/assets/img/foo.jpg"> 

but it does NOT work in angular library

Piosek
  • 220
  • 1
  • 4
  • 15
  • 2
    Can you show an example of what isn't working? Just `` should work. Square brackets in Angular (e.g `[src]`) are template expressions and will bind to a property, that's probably not what you want. – Boxiom Sep 24 '21 at 06:25
  • I'm sorry I could describe it a little bit better. Yes, indeed, your example works perfect in angular project, but it does NOT work in angular library – Piosek Sep 24 '21 at 07:24
  • 1
    Ah, understood. I have no experience with Angular libraries, but maybe [this article](https://newbedev.com/include-assets-when-building-angular-library) is helpful? – Boxiom Sep 24 '21 at 10:11
  • Hi @Piosek, I've already answered your question [here](https://stackoverflow.com/a/64589400/11135174). But you have to export the assets to make them accessible from another project – Raphaël Balet Mar 21 '22 at 12:22
  • Does this answer your question? [Include assets when building angular library](https://stackoverflow.com/questions/57741052/include-assets-when-building-angular-library) – Raphaël Balet Mar 21 '22 at 12:22

1 Answers1

0

Your path to assets folder is not correct. Look your ng-package and assets folder of your library. It should be "assets": ["src/assets"].