Skip to content
Advertisement

How should I reference assets in angular custom element (Web Components)

I have created a web component and I referenced image from my asset folder in there

as below

JavaScript

on local everything is fine, I published my custom element to firebase host and javascript, css and asset folder already exist on my host.

then I tried to use my web component in another html peage as below

JavaScript

and served this via a local http server (http-server)

The problem is images are loading from ./assets/bot.png which doesn’t exist in in the hosted website, and they exists on my published website in firebase.

I know that I can refer them by a full url, but also I think there is a obvious solution and I missed.

I appreciate help

Advertisement

Answer

One option would be to embed the image as data instead of a link:

JavaScript

This will create a component that is 100% self contained instead of relying on two, or more, files.

This does increase the size of your HTML file, but if your images are all fairly small then it shouldn’t matter much.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement