0

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?

3
  • try binding it with [src]="selectedImage" and see if it works Commented Jan 10, 2018 at 10:21
  • it could be a path issue here, any errors in console? Commented Jan 10, 2018 at 10:35
  • Check this stackoverflow.com/questions/45040843/… Commented Jan 10, 2018 at 10:36

2 Answers 2

2

use [src] instead of src

<img [src]="selectedImage" alt="" />
Sign up to request clarification or add additional context in comments.

Comments

0

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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.