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 ?
Please try this
{{friends['my name']}}
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With