[Angular 2] *ngFor
heros.ts:
import {Component} from "@angular/core"; const HEROES = [
{id: 1, name:'Superman'},
{id: 2, name:'Batman'},
{id: 5, name:'BatGirl'},
{id: 3, name:'Robin'},
{id: 4, name:'Flash'}
]; @Component({
selector:'heroes',
styleUrls: [
'heroes.component.css'
],
template: `
<table>
<thead>
<th>Name</th>
<th>Index</th>
</thead>
<tbody>
<tr *ngFor="let hero of heroes; let i = index; trackBy: trackBy(hero);
let isEven=even; let isFirst=first; let isLast=last;"
[ngClass]="{'even': isEven, 'first': isFirst, 'last': isLast}">
<td>{{hero.name}}</td>
<td>{{i}}</td>
</tr>
</tbody>
</table>
`
})
export class Heroes {
heroes = HEROES; trackBy(hero){
return hero ? hero.id: undefined;
}
}
here we can also use:
trackBy: hero?.id
heroes.component.css:
.even{
background: lightgray;
} .first{
font-weight: bold;
} .last{
color: white;
background: black;
}
[Angular 2] *ngFor的更多相关文章
- [Angular 2] *ngFor with index
Let's see how to track index when we use 'ngFor: <li *ngFor="#hero of heros | async, #i = in ...
- [译] Angular 2 VS. React: 血色将至
Angular 2 VS. React: 血色将至 原文链接:https://medium.com/@housecor/angular-2-versus-react-there-will-be-blo ...
- React vs Angular 2: 冰与火之歌
黄玄 · 3 个月前 本文译自 Angular 2 versus React: There Will Be Blood ,其实之前有人翻译过,但是翻得水平有一点不忍直视,我们不希望浪费这篇好文章. 本 ...
- 手把手教你使用Vue/React/Angular三大框架开发Pagination分页组件
DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师.官方网站:devui.designNg组件库:ng-devui(欢迎S ...
- Angular2入门系列教程2-项目初体验-编写自己的第一个组件
上一篇 使用Angular-cli搭建Angular2开发环境 Angular2采用组件的编写模式,或者说,Angular2必须使用组件编写,没有组件,你甚至不能将Angular2项目启动起来 紧接着 ...
- Material使用07 MatGridListModule的使用
1 MatGridListModule简介 对相似数据的展现,尤其是像是图片的展示 使用起来很像表格 官方文档:点击前往 2 MatGridListModule提供的指令 2.1 mat-grid-l ...
- Material使用07 MdGridListModule的使用
1 MatGridListModule简介 对相似数据的展现,尤其是像是图片的展示 使用起来很像表格 官方文档:点击前往 2 MatGridListModule提供的指令 2.1 mat-grid-l ...
- [Angular 2] More on *ngFor, @ContentChildren & QueryList<>
In previous artical, we introduce the how to use *ngFor. The limitation for previous solution to dis ...
- [Angular 2] Using ng-for to repeat template elements
This lesson covers Angular 2’s version of looping through data in your templates: ng-for. It’s conce ...
随机推荐
- 第一个简单的android项目
开发平台:windows7+Eclipse+andriod SDK(24.0)+ADT(23.0.4).这个环境的搭建在前一篇文章(Mobile testing下的appium测试)里面已经描述了. ...
- uC/OS - III 移植 IAR平台
关于移植uC/OS-III 网上已经有很多教程了此处只是做个记录 首先下载源码然后解压得到下面的文件: 然后在模版工程里新建各种文件夹: 最后全部都添加进工程: OK了,编译一下,惊呆了,竟然 0错误 ...
- IOS-day02_OC中类的声明
在上一个笔记中类的使用中,在编译链接的时候会有警告,原因就是我们没有对类进行声明 类的声明如下:使用关键字@interface #import <Foundation/Foundation.h& ...
- const 常量数据,只读
网上其他的博客地址:1 http://www.cnblogs.com/ronny/p/3672501.html 2 http://www.cnblogs.com/hellogiser/p/cplusp ...
- SVM核函数与软间隔
核函数 在上文中我们已经了解到使用SVM处理线性可分的数据,而对于非线性数据需要引入核函数的概念它通过将数据映射到高维空间来实现线性可分.在线性不可分的情况下,支持向量机通过某种事先选择的非线性映射( ...
- 在Heroku上部署MEAN
说明:个人博客地址为edwardesire.com,欢迎前来品尝. Heroku是国外普遍使用大受好评的PaaS,支持Nodejs,基础服务(Nodejs+MongoDB)基本都是免费的.搭建MEAN ...
- linux 系统常用命令
临时性的完全关闭防火墙,可以不重启机器: #/etc/init.d/iptables status ##查看防火墙状态 #/etc/init.d/iptable stop ...
- android sdk manager 闪退 打不开问题
android sdk manager 闪退 打不开问题 环境 win8系统 如果访问不了 dl-ssl.google.com 网址,在C:\Windows\System32\Drivers\etc ...
- lipo命令
工作中,xcode工程遇到一个bug file was built for archive which is not the architecture being linked armv7 找了一些资 ...
- Another mysql daemon already running with the same unix socket
在国外网站发现的解决方法. 原因多个Mysql进程使用了同一个socket. 两个方法解决: 第一个是立即关机 使用命令 shutdown -h now 关机,关机后在启动,进程就停止了. 第二个直接 ...