angular学习笔记(七)-迭代1

时间:2014-05-09 03:44:07   收藏:0   阅读:183

本篇介绍angular中元素的迭代:

bubuko.com,布布扣
<!DOCTYPE html>
<html ng-app>
<head>
  <title>4.1.迭代</title>
  <meta charset="utf-8">
  <script src="../angular.js"></script>
  <script src="script.js"></script>
</head>
<body>
  <ul ng-controller="StudentList">
    <li ng-repeat="student in students">
      <span class="index">{{$index+1}}</span><span class="name"><a href="/student/view/{{student.id}}" class="name">{{student.name}}</a></span><span
            class="score">{{student.score}}</span>
    </li>
  </ul>
</body>
</html>
bubuko.com,布布扣
function StudentList ($scope){
    $scope.students = [{"name":"code_bunny","score":"100","id":"001"},{"name":"white_bunny","score":"90","id":"002"},{"name":"black_bunny","score":"80","id":"003"}]
}

 

ng-repeat="student in students

使用ng-repeat属性来迭代当前元素,其中
in 之后的
students,是当前作用域下的students变量
in之前的student是自己取的名字,作为下面的{{}}中当前被循环到的数据的名字.
$index是迭代的索引值,表示当前迭代到第几条了.从0开始


 

angular学习笔记(七)-迭代1,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!