ng-repeat

Download angularjs eBook

Introduction

The ngRepeat directive instantiates a template once per item from a collection. The collection must be an array or an object. Each template instance gets its own scope, where the given loop variable is set to the current collection item, and $index is set to the item index or key.

Syntax

  • <element ng-repeat="expression"></element>
  • <div ng-repeat="(key, value) in myObj">...</div>
  • <div ng-repeat="variable in expression">...</div>

Parameters

VariableDetails
$indexnumber iterator offset of the repeated element (0..length-1)
$firstboolean true if the repeated element is first in the iterator.
$middleboolean true if the repeated element is between the first and last in the iterator.
$lastboolean true if the repeated element is last in the iterator.
$evenboolean true if the iterator position $index is even (otherwise false).
$oddboolean true if the iterator position $index is odd (otherwise false).

Remarks

AngularJS provides these parameters as special variables that are available in the ng-repeat expression and anywhere inside of the HTML tag on which the ng-repeat lives.

Related Examples

Stats

36 Contributors: 4
Tuesday, February 28, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook