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

Tags: , , ,

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

as below

 <img src="./assets/bot.png" alt="{{botTitle}}" />

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

<!DOCTYPE html>
<html lang="en">

    <meta charset="utf-8">
    <base href="/">

    <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, user-scalable=no">

    <title>Test Angular Elements</title>
    <link rel="stylesheet" href="">


    <script type="text/javascript" src=""></script>


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


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

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM0AAAD
 AAAAAElFTkSuQmCC" alt="beastie.png" scale="0">

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.

Source: stackoverflow