ng-repeat 与ng-switch的简单应用
效果如下图所示:

使用表格显示用户信息,当点击某条用户信息时,在其下方展开一行进行展示。
index.html
<!DOCTYPE html> <html ng-app="myApp">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/uikit.css"/>
<link rel="stylesheet" href="../css/my-uikit.css"/>
</head>
<body> <div class="uk-panel" ng-controller="UserCtrl">
<table class="uk-table uk-table-hover uk-table-striped">
<thead class="uk-bg-primary">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody ng-repeat="user in users" ng-click="selectUser(user)"
ng-switch on="isSelected(user)">
<tr>
<td>{{user.name}}</td>
<td>{{user.email}}</td>
</tr>
<tr ng-switch-when="true">
<td colspan="2" class="uk-bg-success">{{user.desc}}</td>
</tr>
</tbody>
</table>
</div> </body> <script src="../js/angular.js"></script>
<script src="index.js"></script>
</html>
index.js
var myApp = angular.module('myApp', []);
myApp.controller('UserCtrl', ['$scope', function($scope){
$scope.users = [
{
name:'张三',
email:'zhangsan@gmail.com',
desc: '张三的详细信息...'
},
{
name:'李四',
email:'lisi@123.com',
desc: '李四的详细信息...'
},
{
name:'王五',
email:'wangwu@qq.com',
desc: '王五的详细信息...'
}
];
$scope.selectUser = function(user){
$scope.selectedUser = user;
};
$scope.isSelected = function(user){
return $scope.selectedUser === user;
};
}]);
:ng-repeat指令用于渲染集合元素,并持续监视数据源的变化,只要数据源发生变化,其会立即重新渲染视图模板,ng-repeat经过了高度的优化,以便于对DOM书的影响最小化。
:ng-switch on 结合ng-switch-when使用,还有ng-switch-default,其用法与java重点switch用法差不多,on用于制定参数值,ng-switch-when类似于case 。
ng-repeat 与ng-switch的简单应用的更多相关文章
- Part 6 AngularJS ng repeat directive
ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we ...
- zoj 1622 Switch 开关灯 简单枚举
ZOJ Problem Set - 1622 Switch Time Limit: 2 Seconds Memory Limit: 65536 KB There are N lights i ...
- Angular6之ng build | ng build --aot | ng build --prod 差异
由于写了大半年的项目终于要告一段落并且即将进行第二阶段优化开发,emmm 基础版本已经二十多个模块了,必不可少的优化是很重要的,尽管项目上使用多层嵌套懒加载,但是在首屏加载的时候,任然很慢啊,因为一直 ...
- 在库中使用schematics——ng add与ng update
起步 创建一个angular库 ng new demo --create-application=false ng g library my-lib 可见如下目录结构 ├── node_modules ...
- 使用if和switch制作简单的年龄生肖判断
-年 查询 --> var oDiv =document.getElementById("cont"); var oYear = document.getElementByI ...
- Part 14 ng hide and ng show in AngularJS
ng-hide and ng-show directives are used to control the visibility of the HTML elements. Let us under ...
- Angular 中后台前端解决方案 - Ng Alain 介绍
背景 之前项目使用过vue.js+iview,习惯了后端开发的我,总觉得使用不习惯,之前分析易企秀前端代码,接触到了angular js,完备的相关功能,类似后端开发的体验,让人耳目一新,全新的ang ...
- Flume NG高可用集群搭建详解
.Flume NG简述 Flume NG是一个分布式,高可用,可靠的系统,它能将不同的海量数据收集,移动并存储到一个数据存储系统中.轻量,配置简单,适用于各种日志收集,并支持 Failover和负载均 ...
- FLUME NG的基本架构
Flume简介 Flume 是一个cloudera提供的 高可用高可靠,分布式的海量日志收集聚合传输系统.原名是 Flume OG (original generation),但随着 FLume 功能 ...
- angular 2 - 001 ng cli的安装和使用
angular cli 创建项目和组件 ng new my-app --skip-install cd my-app cnpm install ng serve localhost:4200 angu ...
随机推荐
- Gson JsonParser的使用
package iotest; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gso ...
- 编译Qt 4.7.3的时候发生NMAKE : fatal error U1077: 'cd' : return code '0x2'
怀疑是configure的时候没加-nomake demos -nomake examples的问题 references: http://stackoverflow.com/questions/10 ...
- js深入研究之神奇的匿名函数类生成方式
<script type="text/javascript"> var Book = (function() { // 私有静态属性 ; // 私有静态方法 funct ...
- bzoj1676[Usaco2005 Feb]Feed Accounting 饲料计算
Description Farmer John is trying to figure out when his last shipment of feed arrived. Starting wit ...
- window环境下安装 pip 工具 【pip为Python的扩展管理工具】
Python有一些扩展管理工具,例如easy_install和pip工具,我推荐各位使用pip工具,因为pip工具具有很好的安装和卸载体验. 我们首先需要打开pip的官方网站, 下载必要的文件包,然后 ...
- java获取项目地址或tomcat绝对地址
在java项目中获取文件的路径,不管是相对路径还是绝对路径,其本质都是通过绝对路径去寻找. 获取项目地址 request.getSession().getServletContext().getRea ...
- ASP.NET简单文件上传
一>使用FileUpload控件,将其拖入页面: <%@ Page Title="hehe" Language="C#" MasterPageFil ...
- UESTC 1811 Hero Saving Princess
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11104265 题目链接 :http://222.197.181.5/proble ...
- [Cycle.js] Fine-grained control over the DOM Source
Currently in our main() function, we get click$ event. function main(sources) { const click$ = sour ...
- java接口传递数据的实例
我们要讲E类中的数据变化通知A类,这样通过接口F来实现.具体原理就是E的每次数据改变都让其通知接口:而A类继承接口,所以每次E的调用接口都会触发A类的数据更改事件的触发. 首先创建一个类E: publ ...