This is for an Angular 5 / Ionic 3 application. I have a div where I display user generated html from a rich text editor:
<div [innerHtml]='text'></div>
This data can include <a href>
links for which I need to capture the click event in order to force opening in the system's default browser.
I made a directive that works flawlessly for static content but will not affect anything inside the innerHtml element.
import { Directive, Input, HostListener } from "@angular/core";
import { InAppBrowser } from "@ionic-native/in-app-browser";
@Directive({
selector : '[href]'
})
export class PreventLink {
@Input() href;
constructor( private iab: InAppBrowser ) {};
@HostListener('click', ['$event'])
public onClick( event: Event ) {
if( event && this.href ) {
if( this.href.length > 0 ){
this.iab.create( this.href, '_system' );
}
event.preventDefault();
return false;
}
};
};
Any ideas to achieve what I need would be appreciated.