1

Im trying to access the property of an array of objects by the current id in a loop.

<tr ng-repeat="feature in element.features">
    <td>{{ available_features | filter:{id: feature.feature_id} }}</td>
    <td>x</td>
</tr>

Available_features:
{
    id: 1
    name: "Feature 1"
},
{
    id: 2
    name: "Feature 2"
},
{
    id: 3
    name: "Feature 3"
},

element.features is an array of ids, the id references the id in the available_features array.
This outputs the object but I want the .name property.

UPDATE: Seems It works by:

<td>{{ (available_features | filter:{id: feature.feature_id})[0].name }}</td>

1 Answer 1

2

One option:

<td>{{ (available_features | filter:{id: feature.feature_id})[0].name }}</td>

Another option is to change the available_features array to an object and use the id as key, so that you could do something like this:

<td>{{ available_features[feature.feature_id].name }}</td>
Sign up to request clarification or add additional context in comments.

1 Comment

Just after I updated my question with this solution, yours was here :P Yeah I came to the first option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.