angular.module.ng.$compileProvider.directive.ng-repeat

Description

The ng-repeat directive instantiates a template once per item from a collection. 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.

Special properties are exposed on the local scope of each template instance, including:

Usage

as attribute
<ANY ng-repeat="{repeat_expression}">
   ...
</ANY>
as class
<ANY class="ng-repeat: {repeat_expression};">
   ...
</ANY>

Directive info

  • This directive creates new scope.
  • This directive executes at priority level 1000.

Parameters

Example

This example initializes the scope to a list of names and then uses ng-repeat to display every person:

        <div ng-init="friends = [{name:'John', age:25}, {name:'Mary', age:28}]">
          I have {{friends.length}} friends. They are:
          <ul>
            <li ng-repeat="friend in friends">
              [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old.
            </li>
          </ul>
        </div>
      
         it('should check ng-repeat', function() {
           var r = using('.doc-example-live').repeater('ul li');
           expect(r.count()).toBe(2);
           expect(r.row(0)).toEqual(["1","John","25"]);
           expect(r.row(1)).toEqual(["2","Mary","28"]);
         });