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 ...
随机推荐
- ng-selected 与ng-options的使用
1:ng-selected用在<option>标签上面,ng-options用在<select>上面,用于动态创建options列表. <form class=" ...
- HADOOP都升级到2.5啦~~~
经过前年的初次接触,现在已大约能理解整个体系啦.MAPREDUCE都改成YARN啦. 不过,还得继续往前走,再能实用... HIVE,HBASE,ZOOKEEPER,, 思路如下: 安装系统,配置网络 ...
- LeetCode_Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- 如何查找到文件以后,带目录一起拷贝到新的目录? cp --parents source destination
如何查找到文件以后,带目录一起拷贝到新的目录? cp --parents source destination
- C语言伪随机数的生成
在stdlib.h中,有两个函数与伪随机数的生成有关:srand和rand.C语言中,随机数表有很多列,srand函数是根据其参数(unsigned类型)来获得一个种子(seed),根据种子来设置从哪 ...
- MySQL查询当前数据上一条和下一条的记录
如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): ) [and other_cond ...
- poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)
Description Bessie noted that although humans have many universities they can attend, cows have none ...
- [Cycle.js] Read effects from the DOM: click events
So far we only had effects that write something to the external world, we are not yet reading anythi ...
- 用JS来计算百钱买百鸡
怎样用一百块买一百只鸡?已知公鸡5块一只,母鸡3块一只,小鸡一块钱3只: 需要用到for循环嵌套,并且通过优化代码,可以加快运行效率. <!DOCTYPE html> <html l ...
- DEV LookUpEdit 使用方法
public class field { public string Name { get; set; } public string Explain { get; set; } } List< ...