Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Image Src in TypeScript

I'm using ionic 2 and want to load a picture during runtime. In the past projects I always did it like this:

bikeImage.src = "data:image/jpeg;base64," + bikeResult.image;

But it doesn't work in TypeScript.

My HTML looks like this.

<img id='bikeImage'/>

It says, that src is a unresolved variable.

I thought that every JavaScript code works in TypeScript as well. Am I wrong?

Does anybody have an idea how to fix this?

Thanks in advance.

like image 567
Luca Trembon Avatar asked Nov 01 '16 11:11

Luca Trembon


Video Answer


1 Answers

You haven't posted how you get element into bikeImage, but it should be:

bikeImage = document.getElementById("bikeImage") as HTMLImageElement;

If you don't type assert it to HTMLImageElement then it will be just an HTMLElement which does not have the src property.

like image 59
Nitzan Tomer Avatar answered Oct 18 '22 03:10

Nitzan Tomer