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?
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?
{{ }}
(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();
You can use ES6 template strings:
this.myStr=`${1+1}`
https://developers.google.com/web/updates/2015/01/ES6-Template-Strings