Reputation: 1605
I have a quick question on AngularJS: I have one property from JSON as
"icon-class": "home"
Now I need to do this in my html page:
<span class="{{sub.icon-class}}"></span>
the sub is some other object here.
But inspecting the DOM, the value of the above expression is always zero (0). I guess the dash(-) is acting like a subtraction here.
How to do it I could not make it resolve.
Please help.
Upvotes: 0
Views: 50
Reputation: 22944
You could do this:
<span class="{{sub['icon-class']}}"></span>
But in general I'd avoid hyphens in variable names
Upvotes: 1
Reputation: 39522
In this case, you can use bracket notation to retrieve the value when the key has non-standard characters:
<span class="{{sub['icon-class']}}"></span>
Read more about accessing properties at MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
Upvotes: 3