Reputation: 16959
I am using the img element like this with a pipe
<img [src]="filename | pathPipe" />
I would like to specify a default image which is used if the image path is broken. Can this be accomplished inside the template e.g. with a [default] property?
Upvotes: 0
Views: 2894
Reputation: 540
Inside the pathPipe if you have something like an async call or downloading an image. You can set a default value using startsWith inside a pipe func.
Upvotes: 0
Reputation: 7050
The img
element provides an error
event, so this should work fine:
<img [src]="filename | pathPipe" (error)="filename = '/path/to/fallback.jpg'" />
Upvotes: 3