Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
How do I display a list of objects based on a specific property in Angularjs?

I have a one to many model of related collections in mongodb where a doc in the child collection includes the id of a doc in the parent collection. I'm trying to display all children when viewing the parent.

When viewing the parent, I have an ng-repeat that displays the entire child collection. I'm struggling with filtering the child collection so that it only displays results that include the parent id.

Here's my HTML:

<div>{{parent.name}}</div>
<div ng-repeat="child in children | filter: {id: {{parent.id}}}">
    {{child.name}}
</div>

Here's my js:

app.controller("parentCtrl", function($scope, $location, $routeParams, $http) {  
    //Get parent 
    $scope.children = [];
    $http.get('/children').success(function(children) {
        $scope.loaded = true;
        $scope.children = children;
    });
});

The code successfully gets the parent and loads all docs in the child collection. Can I use a filter in my ng-repeat to pull just the children? If not, is there a best practice to get docs from a related collection?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

parent.id shouldn't be wrap with interpolation({{}}) as it needs an expression that evaluates against scope.

ng-repeat="child in children | filter: {id: parent.id }"
over 4 years ago · Santiago Trujillo Report

0

You can use this code:

<div>{{parent.name}}</div>
<div ng-repeat="(k, child) in children | filter: {id: parent.id}"
    {{child.name}}
</div>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!