Answer the question
In order to leave comments, you need to log in
How to put a similar router-link on all hrefs?
Hello.
Through the API, I receive a user message in text html format.
My goal is to convert this text into an html object like this:
let valueHtml = document.createElement('div');
valueHtml.innerHTML = value;
(or through Renderer2) <a>
href
href
[routerLink]
<a [routerLink]></a>
Answer the question
In order to leave comments, you need to log in
Hang the usual handlers click
, check the link, if it is local, you do router.navigateByUrl
it and it is useless to hang the event.preventDefault
Directive routerLink
, the angular templates only seem to look like html, this is the code that compiles to js. And directives do not work in live html.
And you don't need to assign innerHTML directly, read this https://angular.io/guide/security
It's
enough to use the directive[innerHTML]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question