4

I want to access the JavaScript object property with a special character in it. ex my object(data) is

{
 no :1 , gender : male , Handedness; : RightHanded
}

On doing

console.log(dataHandedness;);

Script throws an error. How can I access the Handedness; property?

Also for rendering this property is angularjs using

{{ data.Handedness;}} gives null

Prateek
  • 299
  • 3
  • 18
  • @pointy : this is more related to angularJS – Prateek Nov 16 '14 at 20:13
  • Angular is still JavaScript (well except for that parts that aren't :) The issue is the same; I think that Angular expression might work as `{{ data["Handedness;"] }}` but I don't know Angular so I could be wrong. – Pointy Nov 16 '14 at 20:19
  • @Pointy : no it dont works this way , I already try this , now what am I suppose to do should I delete my question as it is marked duplicate it's still unclear to me though :) – Prateek Nov 16 '14 at 20:44
  • Apparently I have awesome magic powers so I reopened the question. I'm going to add something to the title or else somebody else might close it. – Pointy Nov 16 '14 at 20:46
  • 1
    @Pointy Expressions in Angular template `{{ }}` blocks are just plain old JS expressions (with certain restrictions). The way to access an object property, whether with dot notation or bracket notation, is exactly the same as in JS. –  Jun 05 '17 at 02:48

1 Answers1

1

AngularJS does nothing special here. Refer to the regular rules for referencing properties in a javascript object.

In a controller: console.log($scope.data['Handedness;'])

In a view: {{ data['Handedness;'] }}

Adam Waselnuk
  • 950
  • 1
  • 8
  • 10