1

I have an array and I want to filter to get to a record that matches some other value so I'm doing this:

jobsCtrl.matchList | filter: {job_id: job.id}

Where the controller's matchList looks like this:

[{ job_id: 1, prop: 5},{job_id: 2, prop: 10 } ... ]

If I just output it like this it works: { job_id: 1, prop: 5}

But I want to access the prop property in the DOM, I would expect this to work:

{{ (jobsCtrl.matchList | filter: {job_id: job.id}).prop }}

But that just reads blank, is there a way to do this?

Thanks!

0

2 Answers 2

2

Since filter returns an array you can't directly access an object property of array.

You can however return the first element of the array and get the value of it's property

{{ (jobsCtrl.matchList | filter: {job_id: job.id})[0].prop }}

You wouldn't want to use this too much though, such as inside ng-repeat as it would be quite expensive . Keep in mind that digests may run multiple times each scope change

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

Oh because you end up with an array after the filter. Seems obvious now. Thank you!
To be honest I've never done this but I know times I would have liked to. Gave me a new idea/ tool
0

Would this approach work for you?

<div ng-repeat="job in jobsCtrl.matchList | filter: {job_id: job.id}">
    <p>{{job.prop}}</p>
</div>

Comments

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.