Angular学习3

使用Angular Js创建一个表格

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
    <style>
    table, th , td {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
    }
    table tr:nth-child(odd) {
      background-color: #f1f1f1;
    }
    table tr:nth-child(even) {
      background-color: #ffffff;
    }
    </style>
</head>
<body>
<div ng-app="myApp" ng-init="str1='12'; str2='34'" ng-controller="myCtrl">
  <p>名字 : <input type="text" ng-model="name"></p>
  <h1>Hello {{name}}</h1>
    <br/>
    <table>
        <thead>
            <tr>
            <td width=100px>学号</td>
            <td width=100px>课程号</td>
            <td width=100px>分数</td>
            </tr>
        </thead>

        <tr  ng-repeat="cou in course |orderBy: 'Sno'">
            <td>{{cou.Sno}}</td>
            <td>{{cou.Cno}}</td>
            <td>{{cou.Grade}}</td>
        </tr>
    </table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl',
     function($scope)
    {
        $scope.name = "angular";
        $scope.course=[{Sno:"021",Cno:"1425",Grade:66},
                      {Sno:"002",Cno:"1425",Grade:67},
                      {Sno:"034",Cno:"1425",Grade:68},
                      {Sno:"004",Cno:"1425",Grade:96}]

    }
);
</script>
</body>
</html>

ng-repeat=”cou in course |orderBy: ‘Sno’”

  • ng-repeat 用于循环访问指定集合中的 元素,集合必须是数组或对象
  • 访问集合元素时遵循:“元素 in 集合” 的语法。如”cou in course |orderBy: ‘Sno’”中cou是一个元素变量,上面course集合元素由控制器中$scope添加元素;“ |orderBy: ‘Sno’”是筛选器,在这里是按照Sno进行排序

运行结果:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值