Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

If I have an array of names like

names = ["Muneeb", "Roshan", "Umar", "Kamil", "Shamseer", "Ajay", "Jasar"]

and I want to filter this array in a way that select two elements from this array which has an index of 3 and 4. How to achieve this by AngularJS ng-repeat? Please advise.

share|improve this question
    
new_names = [names[3], names[4]] – xbonez Feb 25 '16 at 22:06
2  
Try ng-repeat="name in [names[3], names[4]]"? – Ananth Feb 25 '16 at 22:08
3  
Seems highly unlikely that you would only be using hard code index values. Please elaborate on full problem and show what you have attempted – charlietfl Feb 25 '16 at 22:10
up vote 0 down vote accepted

can use an ng-if on the index, something like

<div ng-repeat = "name in names track by $index">
  <div ng-if="$index === 3 || $index === 4">Whatever you want here</div>
</div>
share|improve this answer

You can use ng-bind directive

Here is an example:

HTML

<main ng-app="myApp" ng-controller="MainController">

  <article ng-bind="arr[3]"></article>
  <article ng-bind="arr[4]"></article>

</main>

JS

angular.module('myApp', [])

  .controller('MainController', function($scope) {
    $scope.arr = ['one', 'two', 'three', 'four', 'five'];
  });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.