W
W
waltaki2019-08-12 04:47:57
Angular
waltaki, 2019-08-12 04:47:57

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)
After that, get all the elements from this object , and analyze it . If it is local, that is, it goes to the site itself, then I hang it on it , if not, then I leave everything as it is. Most likely, converting an element from text to an html object, as I do, will not allow you to do this. I made a regular pipe, into which I pass all the html text, it should do everything in my plan and give html to the output, already with . Tell me what should I use? And in general, is this possible? Angular 7.3.0 <a>hrefhref[routerLink]
<a [routerLink]></a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-08-12
@waltaki

Hang the usual handlers click, check the link, if it is local, you do router.navigateByUrlit 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 question

Ask a Question

731 491 924 answers to any question