I'm working on a project in Angular. I found this question, but it's not quite what I need.
I make an API call and get a JSON object back that has twenty plus properties. So a user might have the following properties and then some:
user.Name
user.Nickname
user.DOB
user.FavoriteColor
user.Address
...
I also have an array that looks like this.
$scope.ThePropertiesIWantToShow = [
{ propertyID: 1, displayValue: 'Name' },
{ propertyID: 3 displayValue: 'DOB' },
{ propertyID: 5 displayValue: 'Address' },
I have a table where I'd like to show this data, but I only want certain properties displayed (the ones in the array above). If I wanted to manually show everything in ThePropertiesIWantToShow
, I might do something like this:
<tr ng-repeat="user in users">
<td>{{user.Name}}</td>
<td>{{user.DOB}{</td>
<td>{{user.Address}{</td>
</tr>
However, both the JSON data and ThePropertiesIWantToShow
array are much larger. I'd like to know how to use ng-repeat
to do something like the following pseudocode, so that I don't have to type out each property manually. Plus, if I needed to make changes, I could just change the array, and it would be reflected in multiple places:
for each user in users
for each property in ThePropertiesIWantToShow
<td>user.property</td>
Per the previously linked question, I know that I can do something like this to get all properties:
<tr ng-repeat="user in users">
<td ng-repeat="(property, value) in user">{{value}}</td>
</tr>
but this gives me all the data from the API call, and I'd only like to display the properties provided in the array for each user.