I'm new to Angular 2 and was hoping to get some help from the community. I'm currently trying to implement a dynamic/conditional implementation of ngClass in a <tr>
element of my html view. The trufy used is a variable and its original value comes from a JSON object set on my Componenet:
<td [ngClass] = "{weak : {{jsonInMyComponenet.element}}, neutral : !{{jsonInMyComponenet.element}}}" ></td>
When I use the code above I get this error:
Got interpolation ({{}}) where expression was expected
If I remove the curly brackets I get no errors but the page doesn't render the element, so I can't see the class implementation of weak nor neutral. What am I'm doing wrong?
Don't use [...]
and {{...}}
together. Either the one or the other.
<td [ngClass] = "{'weak' : jsonInMyComponenet.element, 'neutral' : !jsonInMyComponenet.element}" ></td>
{{...}}
is for string interpolation. [...]
interprets the value as expression.