CBastianelli CBastianelli - 16 days ago 4x
AngularJS Question

Hide headers in multiple ng-repeat if no values during filtering

I'm struggling with angularjs! Here's the problem. I've a list of employees from different company to show. Data are like these:

name : "company1",
employees : [
{ name : "emp1"},
{ .. }

I show them using two ng-repeat:

<div ng-repeat="company in companies ">
<div class="header">{{}}</div>
<div ng-repeat="employee in company.employees | filter:search">

Here we are, I want to avoid, during filtering the headers of company with no employees.

Hope you guys are smarter than me :)

<div ng-repeat="company in companies ">
<div class="header" ng-show="results.length>0"> {{}}</div>
<div ng-repeat="employee in company.employees | filter:search as results">

Explaination: after filtering your filtered data will be stored in ressults , which we can use to decide whether to show company name or not