0

I have a template that contains this snippet

<img src="{{ src }}" onerror="this.src='{{ placeholderSrc }}'" />

I couldn't make it work. If I remove the onerror bit:

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

the template works again. If I change placeholderSrc's position:

<img src="{{ src }}" onerror="this.src=''" />
{{ placeholderSrc }}

It works.

It seems to have something to do with onerror but I'm not sure exactly what.

I'm on RC 5.

1 Answer 1

1

Just use the inbuilt events:

<img [src]="src" (error)="src = placeholderSrc" />

Plunker for a working example

Sign up to request clarification or add additional context in comments.

2 Comments

while it makes the template work again, the image source isn't replaced upon an error.
Works like a charm for me - see this Plunker

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.