Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a json which has spaces in key names.

The JSON has the following format

    {
     "response":{"docs":[
        {
          "my name":"krammer",
          "job": "stackexchange"
        }
                }
    }

While using ng-repeat to get the parameters into a list, I use the following code

{{friends.['my name']}}

But this gives an empty output. While

friends.my name

gives an error.

So how can the key names with empty spaces be accessed using AngularJS ?

share|improve this question
    
{{friends['my name']}}?? –  SajithNair Feb 26 '14 at 11:21
    
post your ng-repeat as well plz –  Eugene P. Feb 26 '14 at 11:23
1  
@SajithNair you should have posted it as an answer, because it's obviously the issue. –  dfsq Feb 26 '14 at 11:26

2 Answers 2

up vote 5 down vote accepted

Please try this

{{friends['my name']}}
share|improve this answer

It doesn't have anything to do with angular, this is the way we read props from JavaScript object, here you have a object called friends. so these are all we can do, if we don't have invalid javascript characters for naming in JavaScript, like space and some other:

friends.myname
friends['myname']
friends["myname"]

but when we have those invalid characters we only can do:

friends['my name']
friends["my name"]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.