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

后端 未结 9 1804
抹茶落季
抹茶落季 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 05:13

    I don't think there's a builtin function in angular for doing this, but you can do this by creating a separate scope property containing all the header names, and you can fill this property automatically like this:

    var data = {
      foo: 'a',
      bar: 'b'
    };
    
    $scope.objectHeaders = [];
    
    for ( property in data ) {
      $scope.objectHeaders.push(property); 
    }
    
    // Output: [ 'foo', 'bar' ]
    

提交回复
热议问题