1

Working on a project with Angular, and was curious if there is an 'angular-specific' method to acheive this.

I essentially want to retrieve data starting at a specific item in the array, like the 3rd. You'll see in the html what I was curious if angular provides any type of method or filter.

html

  <div ng-controller="bracketsController">
     <div ng-repeat="bracket in brackets  | limitTo: 2" class="bracket-container left" >
      <div>{{bracket.brackets.single.contestant1}}</div>    
      <div>{{bracket.brackets.single.contestant2}}</div>                
     </div>
   <div ng-repeat="bracket in brackets  | limitTo: 2 SOME **Angular FILTER TO START AT 3**" class="bracket-container right" >
      <div>{{bracket.brackets.single.contestant1}}</div>    
      <div>{{bracket.brackets.single.contestant2}}</div>                
   </div>    
 </div>

js

var bracketsapp = angular.module('bracketsApp', []);

bracketsapp.controller('bracketsController', function($scope){
      $scope.brackets = [
      {
        "brackets": {
            "single": {
                "contestant1": "john doe",
                "contestant2": "jane doe"
            }
        }
      },
      {
        "brackets": {
            "single": {
                "contestant1": "john doe",
                "contestant2": "jane doe"
            }
        }
      },
     {
        "brackets": {
            "single": {
                "contestant1": "john doe",
                "contestant2": "jane doe"
            }
        }
      },
     {
        "brackets": {
            "single": {
                "contestant1": "john doe",
                "contestant2": "jane doe"
            }
        }
      },
     {
        "brackets": {
            "single": {
                "contestant1": "john doe",
                "contestant2": "jane doe"
            }
        }
      }
    ]
   });

Thanks for any tips or suggestion.

2 Answers 2

1

You could just use the .slice method directly on the array:

<div ng-repeat="bracket in brackets.slice(3)" class="bracket-container right" >

Besides that though, there is a discussion they are having currently for the next version of angular to support this as a filter. You can follow along here: https://github.com/angular/angular.js/issues/5355

Sign up to request clarification or add additional context in comments.

1 Comment

ahh very cool. Thanks for the github link as well, would be a cool filter to add
1

You can create you own filter, has mention here: Filter results 6 through 10 of 100 with ng-repeat in AngularJS

app.filter('slice', function() {
  return function(arr, start, end) {
    return (arr || []).slice(start, end);
  };
});

<div ng-repeat="bracket in brackets | slice:3:2">{{item}}</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.