user7397952
user7397952

Reputation:

How to limit repeated number of items in ng-repeat. angularjs?

I'm working in contact card. I need to add Name and contact number in the list. But the condition is Name and contact must be added only 2 times. for ex.

Contact Card-1

  1. Name-A
  2. Name-B
  3. Contact-1
  4. Contact-2

Whenever I click on the button my name and contact get added in the list but with certain condition. My code is

<md-list-item ng-show="showContactList" class="md-2-line" ng-repeat="numbers in contactList track by $index" >
<i ng-show="numbers.type == 'test'" class="material-icons md-avatar-icon">textsms</i>
<i ng-show="numbers.type == 'CELL' || numbers.type == 'EXT'" class="material-icons md-avatar-icon">phone</i>
<div class="md-list-item-text" ng-class="{'md-offset': phone.options.offset }">
<h3>  {{ numbers.type }} </h3>
<p> {{ numbers.value }} </p>
</div>
<i class="material-icons md-avatar-icon add-rm-icon margin-right" ng-click="arrayText.push(numbers);">add</i>
</md-list-item>

Upvotes: 1

Views: 229

Answers (1)

Fabol Lous
Fabol Lous

Reputation: 34

You can use:

<div ng-repeat="item in items | filter:{visible: true} | limitTo: 50"> <p>{{item.id}}</p> </div>

{visible- true} will return a list of all visible items

You can take a look at the angularjs docu for more information on the filter filter. http://docs.angularjs.org/api/ng.filter:filter

Upvotes: 2

Related Questions