Search code examples
arraysangularjsangularjs-ng-repeatscopes

How repeat modelos for a specific marca in this example?


I want to repeat just of chevrolet modelos for example. this is my code

<body ng-controller="marcasController">
  <ul ng-repeat="marca in marcas">
    <li ng-repeat="tipo in marca.modelo">{{tipo.nombre}}</li>
  </ul>
</body>

var app = angular.module('App', []);

app.controller('marcasController', ['$scope', function($scope) {

$scope.marcas =[

    {
      "nombre": "Chevrolet",
      "image": "images/aveo.jpg",
      "modelo": [
        {"nombre":"aveo", "color":"black"},
        {"nombre":"corsa", "color":"yellow"}
        ],
      "tab": "aveo"
    },
    {
      "nombre": "Renault",
      "image": "images/aveo.jpg",
      "modelo": [
        {"nombre":"clio", "color":"black"},
        {"nombre":"sandero", "color":"red"}
        ],
      "tab": "aveo"
    },
  ];


  }])

This expample here http://plnkr.co/edit/JmhcU06dypoCwOzszLom?p=preview


Solution

  • Your need to use a filter:

     <ul ng-repeat="marca in marcas | filter:'chevrolet'">
    

    https://docs.angularjs.org/api/ng/filter/filter