I'm working on a project in angular2, which involves loading an image from a database directly (base64 encoded). In angular1, one could simply load it as follows:
<img data-ng-src="data:image/jpg;base64,{{entry.img}}" />
where entry.img is the raw image data. However, I have no idea how to do this in angular2. I've tried
<img [src]="data:image/jpg;base64,{{entry.img}}" />
but that doesn't work, as angular still tries to load the image from a URL.
Once you have put all the required images in the assets directory open the specific component typescript (. ts) file where you want to serve the image. Now you can add the URL of the image in a variable within the constructor so that it is initialized upon component creation.
Upload the simple image you need to create an application using the command " ng new my-app". You have to open your HTML component and then use the image tag and put the image with a name or with their proper path, such as: <img src=” ../../assets/images/image. jpg” class=” img1”> .
Perhaps you could try this:
<img [src]="'data:image/jpg;base64,'+entry.img" />
assuming that entry
is a property of the component and contains an img
attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With