How to make use of the $ filter AngularJs

3

How can I capture in $scope.personConOferta the person who has oferta

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

  <div ng-repeat="person in personas">
     {{ person }}     
  </div>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $filter) {
    $scope.personas = [
      {
         "Codigo": 1,
         "Name": "alberto",
         "Offerta": [
            {
              "precio": 10000,
              "lugar": "Medellin"
            },
            {
              "precio": 2000000,
              "lugar": "Bogota"
            }
         ]
      },
      {
         "Codigo": 2,
         "Name": "albertoPalacios",
         "Offerta": []
      }
    ]
    $scope.personConOferta = $filter('filter')($scope.personas, { Offerta.length > 0 }, true);
    $scope.personSinOferta = $filter('filter')($scope.personas, { Offerta.length == 0 }, true);
});
</script>

</body>
</html>
    
asked by zerokira 10.04.2018 в 21:26
source

1 answer

4

Activate strict mode so that it only filters you by exact matches. This is done by adding true after the search criteria.

$scope.personAlberto = $filter('filter')($scope.personas, { Name: "alberto" }, true);
$scope.personAlbertoPalacios = $filter('filter')($scope.personas, { Name: "albertoPalacios" }, true);
    
answered by 10.04.2018 / 21:34
source