Reputation:
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
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
Reputation: 1263
use [src]
instead of src
<img [src]="selectedImage" alt="" />
Upvotes: 2