EVOLUTION-MANAGER
Edit File: ngRepeat.html
<a href='https://github.com/angular/angular.js/edit/v1.3.x/src/ng/directive/ngRepeat.js?message=docs(ngRepeat)%3A%20describe%20your%20change...#L3' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a> <a href='https://github.com/angular/angular.js/tree/v1.3.9/src/ng/directive/ngRepeat.js#L3' class='view-source pull-right btn btn-primary'> <i class="glyphicon glyphicon-zoom-in"> </i>View Source </a> <header class="api-profile-header"> <h1 class="api-profile-header-heading">ngRepeat</h1> <ol class="api-profile-header-structure naked-list step-list"> <li> - directive in module <a href="api/ng">ng</a> </li> </ol> </header> <div class="api-profile-description"> <p>The <code>ngRepeat</code> 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 <code>$index</code> is set to the item index or key.</p> <p>Special properties are exposed on the local scope of each template instance, including:</p> <table> <thead> <tr> <th>Variable</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td><code>$index</code></td> <td><a href="" class="label type-hint type-hint-number">number</a></td> <td>iterator offset of the repeated element (0..length-1)</td> </tr> <tr> <td><code>$first</code></td> <td><a href="" class="label type-hint type-hint-boolean">boolean</a></td> <td>true if the repeated element is first in the iterator.</td> </tr> <tr> <td><code>$middle</code></td> <td><a href="" class="label type-hint type-hint-boolean">boolean</a></td> <td>true if the repeated element is between the first and last in the iterator.</td> </tr> <tr> <td><code>$last</code></td> <td><a href="" class="label type-hint type-hint-boolean">boolean</a></td> <td>true if the repeated element is last in the iterator.</td> </tr> <tr> <td><code>$even</code></td> <td><a href="" class="label type-hint type-hint-boolean">boolean</a></td> <td>true if the iterator position <code>$index</code> is even (otherwise false).</td> </tr> <tr> <td><code>$odd</code></td> <td><a href="" class="label type-hint type-hint-boolean">boolean</a></td> <td>true if the iterator position <code>$index</code> is odd (otherwise false).</td> </tr> </tbody> </table> <p>Creating aliases for these properties is possible with <a href="api/ng/directive/ngInit"><code>ngInit</code></a>. This may be useful when, for instance, nesting ngRepeats.</p> <h1 id="special-repeat-start-and-end-points">Special repeat start and end points</h1> <p>To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending the range of the repeater by defining explicit start and end points by using <strong>ng-repeat-start</strong> and <strong>ng-repeat-end</strong> respectively. The <strong>ng-repeat-start</strong> directive works the same as <strong>ng-repeat</strong>, but will repeat all the HTML code (including the tag it's defined on) up to and including the ending HTML tag where <strong>ng-repeat-end</strong> is placed.</p> <p>The example below makes use of this feature:</p> <pre><code class="lang-html"><header ng-repeat-start="item in items"> Header {{ item }} </header> <div class="body"> Body {{ item }} </div> <footer ng-repeat-end> Footer {{ item }} </footer> </code></pre> <p>And with an input of <a href="" class="label type-hint type-hint-object">['A','B']</a> for the items variable in the example above, the output will evaluate to:</p> <pre><code class="lang-html"><header> Header A </header> <div class="body"> Body A </div> <footer> Footer A </footer> <header> Header B </header> <div class="body"> Body B </div> <footer> Footer B </footer> </code></pre> <p>The custom start and end points for ngRepeat also support all other HTML directive syntax flavors provided in AngularJS (such as <strong>data-ng-repeat-start</strong>, <strong>x-ng-repeat-start</strong> and <strong>ng:repeat-start</strong>).</p> </div> <div> <h2>Directive Info</h2> <ul> <li>This directive creates new scope.</li> <li>This directive executes at priority level 1000.</li> </ul> <h2 id="usage">Usage</h2> <div class="usage"> <ul> <li>as attribute: <pre><code><ANY ng-repeat=""> ... </ANY></code></pre> </li> </div> <h2 id="animations">Animations</h2> <p><strong>.enter</strong> - when a new item is added to the list or when an item is revealed after a filter</p> <p><strong>.leave</strong> - when an item is removed from the list or when an item is filtered out</p> <p><strong>.move</strong> - when an adjacent item is filtered out causing a reorder or when the item contents are reordered</p> <a href="api/ngAnimate/service/$animate">Click here</a> to learn more about the steps involved in the animation. <section class="api-section"> <h3>Arguments</h3> <table class="variables-matrix input-arguments"> <thead> <tr> <th>Param</th> <th>Type</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td> ngRepeat </td> <td> <a href="" class="label type-hint type-hint-repeat_expression">repeat_expression</a> </td> <td> <p>The expression indicating how to enumerate a collection. These formats are currently supported:</p> <ul> <li><p><code>variable in expression</code> – where variable is the user defined loop variable and <code>expression</code> is a scope expression giving the collection to enumerate.</p> <p>For example: <code>album in artist.albums</code>.</p> </li> <li><p><code>(key, value) in expression</code> – where <code>key</code> and <code>value</code> can be any user defined identifiers, and <code>expression</code> is the scope expression giving the collection to enumerate.</p> <p>For example: <code>(name, age) in {'adam':10, 'amalie':12}</code>.</p> </li> <li><p><code>variable in expression track by tracking_expression</code> – You can also provide an optional tracking function which can be used to associate the objects in the collection with the DOM elements. If no tracking function is specified the ng-repeat associates elements by identity in the collection. It is an error to have more than one tracking function to resolve to the same key. (This would mean that two distinct objects are mapped to the same DOM element, which is not possible.) Filters should be applied to the expression, before specifying a tracking expression.</p> <p>For example: <code>item in items</code> is equivalent to <code>item in items track by $id(item)</code>. This implies that the DOM elements will be associated by item identity in the array.</p> <p>For example: <code>item in items track by $id(item)</code>. A built in <code>$id()</code> function can be used to assign a unique <code>$$hashKey</code> property to each item in the array. This property is then used as a key to associated DOM elements with the corresponding item in the array by identity. Moving the same object in array would move the DOM element in the same way in the DOM.</p> <p>For example: <code>item in items track by item.id</code> is a typical pattern when the items come from the database. In this case the object identity does not matter. Two objects are considered equivalent as long as their <code>id</code> property is same.</p> <p>For example: <code>item in items | filter:searchText track by item.id</code> is a pattern that might be used to apply a filter to items in conjunction with a tracking expression.</p> </li> <li><p><code>variable in expression as alias_expression</code> – You can also provide an optional alias expression which will then store the intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message when a filter is active on the repeater, but the filtered result set is empty.</p> <p>For example: <code>item in items | filter:x as results</code> will store the fragment of the repeated items as <code>results</code>, but only after the items have been processed through the filter.</p> </li> </ul> </td> </tr> </tbody> </table> </section> <h2 id="example">Example</h2><p>This example initializes the scope to a list of names and then uses <code>ngRepeat</code> to display every person: <div> <a ng-click="openPlunkr('examples/example-example88')" class="btn pull-right"> <i class="glyphicon glyphicon-edit"> </i> Edit in Plunker</a> <div class="runnable-example" path="examples/example-example88" module="ngAnimate" deps="angular-animate.js" animations="true"> <div class="runnable-example-file" name="index.html" language="html" type="html"> <pre><code><div ng-init="friends = [ {name:'John', age:25, gender:'boy'}, {name:'Jessie', age:30, gender:'girl'}, {name:'Johanna', age:28, gender:'girl'}, {name:'Joy', age:15, gender:'girl'}, {name:'Mary', age:28, gender:'girl'}, {name:'Peter', age:95, gender:'boy'}, {name:'Sebastian', age:50, gender:'boy'}, {name:'Erika', age:27, gender:'girl'}, {name:'Patrick', age:40, gender:'boy'}, {name:'Samantha', age:60, gender:'girl'} ]"> I have {{friends.length}} friends. They are: <input type="search" ng-model="q" placeholder="filter friends..." /> <ul class="example-animate-container"> <li class="animate-repeat" ng-repeat="friend in friends | filter:q as results"> [{{$index + 1}}] {{friend.name}} who is {{friend.age}} years old. </li> <li class="animate-repeat" ng-if="results.length == 0"> <strong>No results found...</strong> </li> </ul> </div></code></pre> </div> <div class="runnable-example-file" name="animations.css" language="css" type="css"> <pre><code>.example-animate-container { background:white; border:1px solid black; list-style:none; margin:0; padding:0 10px; } .animate-repeat { line-height:40px; list-style:none; box-sizing:border-box; } .animate-repeat.ng-move, .animate-repeat.ng-enter, .animate-repeat.ng-leave { -webkit-transition:all linear 0.5s; transition:all linear 0.5s; } .animate-repeat.ng-leave.ng-leave-active, .animate-repeat.ng-move, .animate-repeat.ng-enter { opacity:0; max-height:0; } .animate-repeat.ng-leave, .animate-repeat.ng-move.ng-move-active, .animate-repeat.ng-enter.ng-enter-active { opacity:1; max-height:40px; }</code></pre> </div> <div class="runnable-example-file" name="protractor.js" type="protractor" language="js"> <pre><code>var friends = element.all(by.repeater('friend in friends')); it('should render initial data set', function() { expect(friends.count()).toBe(10); expect(friends.get(0).getText()).toEqual('[1] John who is 25 years old.'); expect(friends.get(1).getText()).toEqual('[2] Jessie who is 30 years old.'); expect(friends.last().getText()).toEqual('[10] Samantha who is 60 years old.'); expect(element(by.binding('friends.length')).getText()) .toMatch("I have 10 friends. They are:"); }); it('should update repeater when filter predicate changes', function() { expect(friends.count()).toBe(10); element(by.model('q')).sendKeys('ma'); expect(friends.count()).toBe(2); expect(friends.get(0).getText()).toEqual('[1] Mary who is 28 years old.'); expect(friends.last().getText()).toEqual('[2] Samantha who is 60 years old.'); });</code></pre> </div> <iframe class="runnable-example-frame" src="examples/example-example88/index.html" name="example-example88"></iframe> </div> </div> </p> </div>