I have a function which detect url links with Regex and replace by a span
tag.
The replacement works fine, the actual problem is: when I use (click)="myFunction()"
on this span
, he doesn't compile with the click event, just add on html.
my function:
insertHrefs(content: string): string {
const links = content.match(/\b(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+/gm);
const linksReplaced = [];
// tslint:disable-next-line: forin
for (const i in links) {
const link = links[i];
if (linksReplaced.find(l => l === link)) { continue; }
content = AppUtils.replaceAll(content, link,
`<span style="color:#357CFF;" (click)="test()">${link}</span>`
);
linksReplaced.push(link);
}
return content;
}
the result: http://prntscr.com/ov8yfc
I need some way to add click event to span
tag dynamically.