user1452221 user1452221 - 5 months ago 24
AngularJS Question

repeating the first line just once ng-repeat

I have a mongodb collection with this parameters:

"_id": ObjectId("59c265235e21f8a8b7d75b23"),
"email": "",
"password": "PlPEVQpAt",
"company_name": "Oyope",
"site": "",
"description": "lorem id ligula suspendisse ornare",
"ads": [{
"id": 19,
"users_apply": [],
"email": "",
"phone": "(847) 2671999",
"location": {
"longtitude": -88.0549221,
"latitude": 42.1165506
"status": "open",
"skills": ["Financial Analysis"],
"scope": "half"

I would like to show the company_name, and all the elements that are in the array "ads".

for that I have done this:

<tr ng-repeat="ad in pubJobs2 | filter:{company_name: search.company_name} | limitTo : 10 : begin()">
<td><a ng-click="loadJob(ad.company_name)">{{ad.company_name}}</a></td>


<tr ng-repeat="adv in | filter:{email:, scope: search.scope} ">
<td><button class="button" ng-click="applyJob(">Apply</button></td>



the problem is that the titles are repeating too.
How could I avoid it?

Answer Source

This isn't using your data, but this shows how you can use the (often misused) ngInit directive to grab a reference to the previous record in an ngRepeat. As you can see, I simply suppress the category unless it has changed from the previous record.

<table >
  <tr ng-repeat="food in $" ng-init="prevFood = $[$index-1]">
    <td>{{prevFood.category !== food.category ? food.category : '&nbsp;'}}</td>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download