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,471
  • 17
  • 87
  • 173
danday74
  • 45,909
  • 39
  • 198
  • 245

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,302
  • 20
  • 27
1

You can use ES6 template strings:

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

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

Dmitrij Kuba
  • 949
  • 9
  • 14