ng-repeat: access key and value for each object in array of objects


ng-repeat: access key and value for each object in array of objects

Problem

I have an array of objects and I am using an ng-repeat to iterate over them, which is easy. The array looks something like this:

$scope.steps = [
{companyName: true},
{businessType: true},
{physicalAddress: true}
];

And my ng-repeat attribute looks like:

<div ng-repeat="step in steps"> ... </div>

In each iteration, step is equal to one of the objects, as expected. Is there anyway to access both the key and the value of the step object? So that I could do something like this:

<div ng-repeat="(stepName, isComplete) in steps"> ... </div>

Where stepName == 'companyName' and isComplete == true. I've tried doing this exact thing but stepName always just ends up being the index of the step object (which makes sense). I'm just trying to figure out if there is another way to write the ng-repeat syntax so that I can get the key and the value.

Thanks for any ideas/suggestions. Much appreciated.

PS. My current work around is to just do this in my controller:

$scope.stepNames = [];
angular.forEach($scope.steps, function(isComplete, stepName){
$scope.stepNames.push({stepName: stepName, isComplete: isComplete});
});

And then to iterate over that, but it would be nice to do it all in the view

Problem courtesy of: tennisgent

Solution

A repeater inside a repeater

<div ng-repeat="step in steps">
<div ng-repeat="(key, value) in step">
{{key}} : {{value}}
</div>
</div>

Solution courtesy of: tymeJV

View additional discussion.