1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00
Files
browser/libs/angular/src/directives/fallback-src.directive.ts
Oscar Hinton ac49e594c1 Add standalone false to all non migrated (#14797)
Adds standalone: false to all components since Angular is changing the default to true and we'd rather not have the angular PR change 300+ files.
2025-05-15 10:44:07 -04:00

24 lines
676 B
TypeScript

// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Directive, ElementRef, HostListener, Input } from "@angular/core";
@Directive({
selector: "[appFallbackSrc]",
standalone: false,
})
export class FallbackSrcDirective {
@Input("appFallbackSrc") appFallbackSrc: string;
/** Only try setting the fallback once. This prevents an infinite loop if the fallback itself is missing. */
private tryFallback = true;
constructor(private el: ElementRef) {}
@HostListener("error") onError() {
if (this.tryFallback) {
this.el.nativeElement.src = this.appFallbackSrc;
this.tryFallback = false;
}
}
}