How can I use ng-repeat on JSON data whose number is the key?

advertisements

I want to use ng-repeat to display the table of data that provide by JSON format like this

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

But my code below seems doesn't 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 it?

Thanks!


{{country.1961}} works fine for me check this JSFiddle, but its better you can use bracket notation instead of dot notation when

  • keys are fully numbers like '1985'
  • keys contains 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>