Angular Way To Set Onerror On Iframe
Is there angular way to setup onerror attribute on iframe so I can use angular expressions. I've tried to use this: bu
Solution 1:
With default events you cant. But you can create a directive and assign to the iframe
. Then in the logic of the directive , register to the onerror
event and write your logic
import { Directive, ElementRef, HostListener, Renderer2, AfterViewInit }
from '@angular/core';
@Directive({
selector: '[appFrame]'
})
export class FrameDirective implements AfterViewInit {
constructor(private iframeEl: ElementRef, private renderer: Renderer2) {
}
ngAfterViewInit() {
this.renderer.listen(this.iframeEl.nativeElement, 'error', () => {
console.log('error caught in directive');
});
}
}
Post a Comment for "Angular Way To Set Onerror On Iframe"