Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda