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 ...
随机推荐
- Qt编程之数据流图(dataflow diagram)的编写
不知道怎么搞. 在网上搜了一些资料,说是有提供的Demo样例 https://forum.qt.io/topic/18472/dataflow-programming-gui/4 http://sta ...
- windows driver inf文件
原来修改了inf文件会导致签名过的驱动包哈希值不正确了啊.现在才知道. = = http://www.chiphell.com/thread-827956-1-1.html
- 函数call相关[ASM]
前言: __cdecl:C/C++函数默认调用约定,参数依次从右向左传递,并压入堆栈,最后由调用函数清空堆栈,这种方式适用于传递参数个数可变的被调用函数,只有被调用函数才知道它传递了多少个参数给被 ...
- leetcode_question_119 Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)
原文网址:http://www.blogjava.net/anchor110/articles/355699.html 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方包,添 ...
- eclipse 添加resources 目录
java项目需要一些配置,配置放置目录如:/src/main/resources; 如果没有这个文件夹,需要右键项目>new>source folder > Folder name ...
- QtWebkit2.2.0 HTML5.0支持情况
Canvas: 支持element, 2d context以及文本 解析规则:支持 HTML5 tokenizer/tree building, SVG in text/html, MathML ...
- 用JS的for循环打印九九乘法表
需要使用两个for循环嵌套,代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- Visual Studio 命中断点时 打印信息
打印时间: 开始: {DateTime.Now.ToString()} 结束: {DateTime.Now.ToString()} 搜索 复制
- Socket学习笔记
..........(此处略去万万字)学习中曲折的过程不介绍了,直接说结果 我的学习方法,问自己三个问题,学习过程将围绕这三个问题进行 what:socket是什么 why:为什么要使用socket ...