Yes, I have been searching through the angular 2 docu and tried already all the different versions, but it didn´t work.
Strangely, now I even get an error with the [inner-html] that says:
Can’t bind to ‘inner-html’ since it isn’t a known native property.
This actually didn´t throw an error before. But I have upgraded to alpha48…maybe that broke it…
Hi,
yes, I have seen that article, too. But as far as I understand it, that is targetting a different use case. I believe he wants to be able to dynamically “execute” html like
So the “my-angular-component” gets expanded to whatever template is defined for it.
My use case is actually very simple: I want to display (read-only) simple text in a <div>{{myText}}</div> that I read from a database. This text has very basic html-tags mainly for line-break:
<div>this is line 1 <br />and here goes line two <br />and here is line 3</div>
That is all I need…it can´t be so difficult, can it?
meanwhile you can always take the string, split it into an array, compare it’s values and you can reconstruct the string-value html in a dynamic template containing your basic html markup. It is even easier if your html string is consistent in it`s markup.
I’ve done this in angular1, but not yet in angular2.
I had a quick look at the documentation and it seems still possible. When I have a bit of time, I’ll try and generate a codepen.
Hopefully they fix [inner-html] in a coming beta release.
The most solid answer is “figure out another way to achieve your goal”. This is deliberately unsupported in Angular 2+, for IMHO very good reasons. Here is one alternative approach.
Sweeet…after trying all the other options this one works.
In my example, binding the inner html to my component variable syntactically worked like this.
<span [innerHTML]=menuOption.title>