1

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 myDirdirectives 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.

Community
  • 1
  • 1
Benjamin
  • 101
  • 1
  • 1
  • 2
  • Maybe I could create a pipe which would parse the string, collect links, and apply behavior on them. I will try that. – Benjamin Mar 26 '17 at 11:58

0 Answers0