你的位置:首页 > 软件开发 > Java > Part 6 AngularJS ng repeat directive

Part 6 AngularJS ng repeat directive

发布时间:2016-01-05 02:00:11
ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we want to do.1. For each employee we ha ...

ng-repeat is similar to foreach loop in C#.  Let us understand this with an example. Here is what we want to do.Script.js : The controll function builds the model for the view. The model employees has the list of all employees.

 var app = angular      .module("myModule", [])      .controller("myController", function ($scope) {         var employees = [          { firstName: "Ben", lastName: "Hastings", gender: "Male", salary: 55000 },          { firstName: "Sara", lastName: "Paul", gender: "Female", salary: 68000 },          { firstName: "Mark", lastName: "Holland", gender: "Male", salary: 57000 },          { firstName: "Pam", lastName: "Macintosh", gender: "Female", salary: 53000 },          { firstName: "Todd", lastName: "Barber", gender: "Male", salary: 60000 }        ];         $scope.employees = employees;      });

Finding the index of an item in the collection : 

  • To find the index of an item in the collection use $index property
  • To get the index of the parent element
    • Use $parent.$index or
    • Use ng-init="parentIndex = $index"

The following example, shows how to retrive the index of the elements from a nested collection

原标题:Part 6 AngularJS ng repeat directive

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。