user8770372
user8770372

Reputation:

Angular Image src not updating although variable is populated

I have the following code:

app.component.html:

<button (click)="updateImage('image1.png')"></button>

<img src="{{selectedImage}}" alt="" />

app.component.ts:

selectedImage;

updateImage(image) {
    this.selectedImage = image;
}

My question is...If image url has been passed, why isn't the image src updating?

Upvotes: 0

Views: 2684

Answers (2)

Stan
Stan

Reputation: 476

Also, ensure that your pathing is correct. The code looks good, but the app may not find your image. There would be an error 404 in your browser console if that were the case.

Try placing the image in your assets folder and linking it with updateImage('/assets/image1.png')

Upvotes: 0

Ashraful Islam
Ashraful Islam

Reputation: 1263

use [src] instead of src

<img [src]="selectedImage" alt="" />

Upvotes: 2

Related Questions