Last active
July 13, 2017 01:04
-
-
Save yoelnacho/b0960e4f2403847eb56c43ac1b3e6abc to your computer and use it in GitHub Desktop.
Angular2 Pipe: Sin imagen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img [src]="artist.images | sinfoto"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'sinfoto' | |
}) | |
export class SinfotoPipe implements PipeTransform { | |
transform(value: any[]): string { | |
let noimage = "assets/img/noimage.png"; | |
if( !value ){ | |
return noimage; | |
} | |
return ( value.length > 0 ) ? value.url : noimage; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment