AngularJS的ng-repeat的内部变量
代码下载:https://files.cnblogs.com/files/xiandedanteng/angularJSng-repeatInnerVariable.rar
代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="notesApp">
<head>
<title> New Document </title>
<style>
.odd{
background-color:red;
width:400px;
}
.even{
background-color:#336699;
width:400px;
}
</style>
<meta charset="utf-8">
<script src="angular1.4.6.min.js"></script>
</head>
<body ng-controller="MainCtrl as ctrl">
<div ng-repeat="(author,member) in ctrl.members" ng-class="ctrl.getBackground({{$odd}})"> <!-- {{$odd}}是辅助变量 是否是奇数行 -->
#{{$index}},id={{member.id}}.name={{author}},age={{member.age}},gender={{member.gender}}<!-- {$index}}是辅助变量索引 -->
<div>
</body>
</html>
<script type="text/javascript">
<!--
angular.module('notesApp',[])
.controller('MainCtrl',[function(){
var self=this;
self.members={
andy:{id:11,age:20,gender:'male'},
bill:{id:12,age:21,gender:'female'},
Cindy:{id:23,age:22,gender:'male'},
douglas:{id:54,age:23,gender:'female'},
Einstein:{id:85,age:24,gender:'male'},
};
// 根据奇偶行决定背景
self.getBackground=function(odd){
if(odd==true){
return 'odd';
}else{
return 'even';
}
};
}]);
//-->
</script>
效果:

要点:
每一个以“$”为前缀的变量都是AngularJS内置的,它可以提供当前元素的统计信息.
AngularJS的ng-repeat的内部变量的更多相关文章
- (已解决)'ng' 不是内部或外部命令,也不是可运行的程序或批处理文件
前言: 之前在安装Angular环境的时候有个问题,就是通过命令成功安装了angular cli脚手架工具,但是在终端(win+r cmd)中输入ng version一直提示的是'ng' 不是内部或外 ...
- 【C语言】C语言外部变量和内部变量
目录: [外部变量] · 定义 · 用extern修饰变量 [内部变量] · 定义 · 用static修饰变量 1.外部变量 · 定义 定义的变量能被本文件和其它文件访问的变量,称为外部变量. 注: ...
- 【转】perl特殊符号及默认的内部变量
perl特殊符号及默认的内部变量,有需要的朋友不妨参考下 Perl的特殊符号 @ 数组 $x{} x名字前面是美元符号($),后面是花 ...
- Linux Shell编程(14)——内部变量
内建变量影响Bash脚本行为的变量.$BASHBash二进制程序文件的路径 bash$ echo $BASH /bin/bash$BASH_ENV该环境变量保存一个Bash启动文件路径,当启动一个脚本 ...
- ng事件中为变量的参数
之前学习Angular时碰到过这种问题,绑定事件中传参为变量的问题. 举个例子吧,比如有这么一段代码: <button type='button' ng-click="showMsg( ...
- 【转】shell学习笔记(三)——引用变量、内部变量、条件测试、字符串比较、整数比较等
1.env显示当前的环境变量 2.PS1='[\u@\h \w \A] \$' 可以设置bash的命令与提示符. 3.echo $$ 显示当前bash的PID号 4.echo $?显示上一条指令的回传 ...
- 2. ansible-playbook 条件语句-内部变量使用
内部变量指的是把变量定义在playbook里面或者是执行结果作为变量 循环语句-标准Loops [root@LeoDevops playb]# cat p_loop.yaml - hosts: u12 ...
- GNU Make - 内部变量的赋值和改变
1. 赋值和显示 采用$(info $(variable_name))显示内部变量 eg: FOO=bar $(info $(FOO)) 运行结果: #: make bar 2. 从命令行外部改变 B ...
- shell编程——内部变量
常用的内部变量有:echo, eval, exec, export, readonly, read, shift, wait, exit 和 点(.) echo:将变量名指定的变量显示到标准输出 [r ...
- 使用内部变量,删除,替换,UNSET,等字符操作
使用内部变量,删除,替换,UNSET,等字符操作 FREDDY=freddy 删除字符串前几2个字符: [root@localhost tmp]# echo ${FREDDY:2} eddy ...
随机推荐
- luogu4173 残缺的字符串
there #include <algorithm> #include <iostream> #include <cstring> #include <cst ...
- python中json操作了解
什么是接口? 交换数据 http://openweathermap.org/current json简介 JSON 是存储和交换文本信息的语法.类似 XML JSON 语法是 JavaScript 语 ...
- python学习-- 理解'*','*args','**','**kwargs'
刚开始学习Python的时候,对有关args,kwargs,和*的使用感到很困惑.相信对此感到疑惑的人也有很多.我打算通过这个帖子来排解这个疑惑(希望能减少疑惑). 让我们通过以下5步来理解: 1. ...
- TOJ 3581: 最简IPv6表示
3581: 最简IPv6表示 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 121 ...
- 台州学院we are without brain 训练 计算几何
A - View Angle Flatland has recently introduced a new type of an eye check for the driver's licence. ...
- Spring中的注解 @Qualifier
在使用Spring框架中@Autowired标签时默认情况下使用 @Autowired 注释进行自动注入时,Spring 容器中匹配的候选 Bean 数目必须有且仅有一个.当找不到一个匹配的 Bean ...
- OGNL表达式详解
OGNL表达式标签中的值有三种: 1.直接是OGNL表达式. 2.字符串需转义自OGNL表达式. 1)OGNL表达式转换为字符串显示,需要用''(单引号)引起来. 2)转为OGNL表达式的字符串,需要 ...
- cf- 297 < a >--字符串操作技巧
A. Vitaliy and Pie time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 898E Squares and not squares
题目大意 给定 $n$($n$ 是偶数,$2\le n\le 2\times 10^{5}$)个非负整数 $a_1,\dots, a_n$($a_i\le 10^9$). 要求将其中 $n/2$ 个数 ...
- [luoguP2763] 试题库问题(最大流)
传送门 每个类别和它所有的试题连一条权值为1的边. 增加一个超级源点s,s和每个类别连一条权值为选当前类别数量的边. 增加一个超级汇点t,每个试题和t连一条权值为1的边. 求最大流即可. ——代码 # ...