Can we add (click)="somemethod()" programmatically?
I am trying to find all the a tags in a div and add the click function so that they would open in In App Browser.
@ViewChild('newsSingleContent') newsDiv: any;
ngAfterViewInit() {
let child = this.newsDiv.nativeElement;
let matches = child.querySelectorAll('a[href]');
matches.forEach((obj) => {
let link = obj.href;
obj.removeAttribute('href');
obj.setAttribute('click', 'launch('+link+')');
});
}
Not sure if it is the proper way to do so, but the problem is, setAttribute doesn’t take “(click)”. If this is not good practice, could you guide me in a proper path?
Thanks