Problem
I have a string coming from the backend, like:
"HTML has an image element. This element can have an alt attribute."
When I display this string in my component template, I would like the user to be able to open a modal by clicking on the words "image" and "alt".
Solution tried
I create an attribute directive myDir
, and changed the backend so it returns me the following string:
"HTML has an <a href="#image" myDir>image</a> element. This element can have an <a href="#alt" myDir>alt</a> attribute."
I know this is bad, to return HTML from the backend, but I didn't know how to do it otherwise.
Unfortunately, it does not work, because the 2 myDir
directives are not executed.
I found this SO question, which I think is similar, but it has no answer: Angular 2 parse dynamic template as string
How could I solve my issue? Is there another way of solving my issue?
In my example there are only 2 words (image and alt), but I actually have a lot of words in my project.
Thanks.