How to iterate over the keys and values with ng-repeat in AngularJS?

后端 未结 9 1789
抹茶落季
抹茶落季 2020-11-22 04:36

In my controller, I have data like: $scope.object = data

Now this data is the dictionary with keys and values from json.

I can acce

9条回答
  •  春和景丽
    2020-11-22 04:58

    You can do it in your javascript (controller) or in your html (angular view)...

    js:

    $scope.arr = [];
    for ( p in data ) {
      $scope.arr.push(p); 
    }
    

    html:

    
        {{k}}
    
    

    I believe the html way is more angular , but you can also do in your controller and retrieve it in your html...

    also not a bad idea to look at the Object keys, they give you the an array of the keys if you need them, more info here:

    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

提交回复
热议问题