How can I use ng-repeat in JSON data that have numbers as a key?

I want to use ng-repeat to display a data table that provides a JSON format like this

{"name":"Aruba","code":"ABW","1960":54208,"1961":55435}, {"name":"Afghanistan","code":"AFG","1960":8774440,"1961":8953544} 

But my code below does not seem to work with {{country.1961}}.

 <table> <tr> <td>Country name</td> <td>1960 population</td> <td>1970 population</td> <td>1980 population</td> <td>1990 population</td> <td>2000 population</td> <td>2010 population</td> <td>Percentage growth between 1960 and 2010</td> </tr> <tr ng-repeat="country in countries"> <td>{{ country.name }}</td> <td>{{ country.1961 }}</td> </tr> </table> 

When I delete <td>{{ country.1961 }}</td> everything works fine. How can i fix this?

Thanks!

+5
source share
2 answers

{{country.1961}} works great for me, check out this JSFiddle , but it's better to use parenthesis notation as dot notation when

  • Keys
  • completely filled with numbers like '1985'. Keys
  • contain spaces like My Place

Jsfiddle

  <table border='1'> <tr> <td>Country name</td> <td>1960 population</td> <td>1970 population</td> <td>1980 population</td> <td>1990 population</td> <td>2000 population</td> <td>2010 population</td> <td>Percentage growth between 1960 and 2010</td> </tr> <tr ng-repeat="country in countries"> <td>{{ country.name }}</td> <td>{{ country['1961'] }}</td> </tr> </table> 
+4
source

You can use note notation {{country['1961']}} .

+2
source

All Articles