How can I capture in $scope.personConOferta
the person who hasoferta
<!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>
Turn on strict mode so it only filters you for exact matches. This is done by adding true after the search criteria.