Angularjs ng repeat directive
An ng-repeat
directive in AngularJS that can be used to create a list of items based on a collection.
The ng-repeat
directive works by repeating a template for each item in a collection, which can be an array or an object. The syntax for using ng-repeat
is as follows:
<div ng-repeat="item in itemList"> {{ item }} </div>Sww:ecruow.theitroad.com
In this example, the ng-repeat
directive is used to repeat a div
element for each item in the itemList
array. The item
variable represents the current item being rendered in the loop, and its value is interpolated inside the div
element using double curly braces.
The ng-repeat
directive also provides additional features, such as filtering, sorting, and pagination, which can be used to manipulate the collection before rendering the items. Here is an example of using ng-repeat
with filtering and sorting:
<input type="text" ng-model="searchText"> <select ng-model="sortBy"> <option value="name">Name</option> <option value="age">Age</option> </select> <div ng-repeat="item in itemList | filter:searchText | orderBy:sortBy"> {{ item.name }} - {{ item.age }} </div>
In this example, the ng-repeat
directive is used to repeat a div
element for each item in the itemList
array after applying a filter based on the searchText
variable and sorting based on the sortBy
variable, which is bound to a select
element. The item
variable represents an object with name
and age
properties, which are interpolated inside the div
element.