mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-09-29 15:30:53 -04:00
32 lines
621 B
TypeScript
32 lines
621 B
TypeScript
import { Directive, ElementRef, HostListener, Input, Pipe, PipeTransform } from "@angular/core";
|
|
|
|
/* eslint-disable @angular-eslint/directive-selector */
|
|
@Directive({
|
|
selector: "img[fallback]"
|
|
})
|
|
export class FallbackDirective
|
|
{
|
|
@Input() fallback: string;
|
|
|
|
constructor(private img: ElementRef) { }
|
|
|
|
@HostListener("error")
|
|
onError(): void
|
|
{
|
|
const html: HTMLImageElement = this.img.nativeElement;
|
|
html.src = this.fallback;
|
|
}
|
|
}
|
|
|
|
@Pipe({
|
|
name: "fallback",
|
|
pure: true
|
|
})
|
|
export class FallbackPipe implements PipeTransform
|
|
{
|
|
transform(value: any, ...args: any[]): any
|
|
{
|
|
return value ?? args.find(x => x);
|
|
}
|
|
}
|