1

I have:

<div [innerHtml]="myStr">

where:

this.myStr=='{{1+1}}'

I want it to display:

2

But it outputs:

{{1+1}}

In Angular1 $compile was used for this issue. What do we use in Angular2 to compile expressions?

halfer
  • 19,824
  • 17
  • 99
  • 186
danday74
  • 52,471
  • 49
  • 232
  • 283

2 Answers2

1

{{ }} (double brackets) signals angular to interpolate values on the View, or client, not in the component class. You just want to set the value of this.myStr like a normal string variable in javascript.

following your example, you would use

this.myStr = '' + (1 + 1);

or

this.myStr = (1 + 1).toString();
Neil S
  • 2,304
  • 21
  • 28
1

You can use ES6 template strings:

this.myStr=`${1+1}`

https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

Dmitrij Kuba
  • 998
  • 9
  • 14