[Angular 2] Property Binding
2016-04-06 03:23
405 查看
Property Binding is bind property NOT attribute!
So 'class' is attribute on DOM, but 'class.active' is an property.
'aria-label' is attribute, so need to write like 'attr.aria-label'.
If you don't like use 'class.active', you can use 'ngClass' as shown in commnets
import {Component, Input, Output, EventEmitter} from 'angular2/core'; @Component({ selector: 'hero-item', styles: [ '.active {color: red}' ], template: ` <li [class.active]="isSelected" [attr.aria-label]="hero.name" (click)="selectHero(hero)"> {{hero.name}} </li> ` }) // <li [ngClass]="{active: isSelected}"></li> export class HeroItem{ label="This is a super hero"; isSelected = false; @Input() hero ; @Output() changed = new EventEmitter(); constructor(){ } selectHero(hero){ this.changed.emit(hero); this.isSelected = true; } }
So 'class' is attribute on DOM, but 'class.active' is an property.
'aria-label' is attribute, so need to write like 'attr.aria-label'.
If you don't like use 'class.active', you can use 'ngClass' as shown in commnets
相关文章推荐
- CentOS7中禁用IPV6
- uva 10801 Lift Hopping
- 完全用linux工作,放弃windows
- ssh客户端CRT连接linux使用技巧
- CentOS环境搭建(JDK安装、mysql安装、hadoop安装等)
- centos7安装hadoop
- linux下gcc默认搜索头文件及库文件的路径
- linux制作livecd
- How to install OpenBazaar Server in CentOS7
- Linux启动Eclipse时指定jdk的三种方法
- -Dmaven.multiModuleProjectDirectory system propery is not set.
- 利用maven中resources插件的copy-resources目标进行资源copy和过滤
- 主要电商网站首屏性能对比
- Centos 7 安装Mono和Jexus 默认目录安装 (一)
- Linux进阶之bash编程(流程控制if-else)
- Linux chmod 修改多个文件权限
- OpenGL实践4之索引绘制
- hadoop安装
- 自研轻量级分布式实时计算框架light_drtc
- CentOS 7.0如何将iptables作为防火墙(默认使用的是firewall作为防火墙)