[Angular 2] Property Binding
Property Binding is bind property NOT attribute!
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
[Angular 2] Property Binding的更多相关文章
- Unity3D学习笔记——NGUI之Property Binding
Property Binding:用于绑定两个组件,然后可以将一个组件的信息发送给另一个组件. 效果图如下: 一:使用步骤 1.建立一个Sprite 2.建立一个Label 3.为Sprite添加Pr ...
- 从 SimpleIntegerProperty 看 Java属性绑定(property binding) 与 观察者模式(Observable)
//TODO:ExpressionHelper .bindBidirectional双向绑定.以及IntegerExpression的一系列算术方法和返回的IntegerBinding暂未详细解析(比 ...
- [AngularJS - thoughtram] Exploring Angular 1.3: Binding to Directive Controllers
The post we have: http://www.cnblogs.com/Answer1215/p/4185504.html gives a breif introduce about bin ...
- [译]Exploring Angular 1.3: Binding to Directive Controllers
原文: http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html Angul ...
- Event Binding in Angular
https://www.pluralsight.com/guides/angular-event-binding Introduction In this guide, we will explore ...
- angular学习(二)—— Data Binding
转载请写明来源地址:http://blog.csdn.net/lastsweetop/article/details/51182106 Data Binding 在angular中.model和vie ...
- 【Angular 5】数据绑定、事件绑定和双向绑定
本文为Angular5的学习笔记,IDE使用Visual Studio Code,内容是关于数据绑定,包括Property Binding.Class Binding.Style Binding. 在 ...
- angular学习3
#创建了一个component 查看angular.json文件: "prefix":"app", 在所创建的component的selector上添加了app ...
- Angular 2 Architecture Overview
Module 简单来说模块(module)就是完成共同目的的代码块,export一些内容例如一个类.函数.或值变量. component就是一个基本的Angular块,一个component类其实也是 ...
随机推荐
- Jquery.Sorttable 桌面拖拽自定义
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- cognos开发与部署报表到广西数据质量平台
1.cognos报表的部署. 参数制作的步骤: 1.先在cognos里面把做好的报表路径拷贝,然后再拷贝陈工给的报表路径. 开始做替换,把陈工给的报表路径头拿到做好的报表路径中,如下面的链接http: ...
- Windows 设置时间同步
1.Windows Server 2008 r2 注:{}内是你要同步的外部服务器地址,例如复旦的时间同步服务器地址为:ntp.fudan.edu.cn,则完整命令如下: w32tm /config ...
- ajax+FormData+javascript 实现无刷新表单注册
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 武汉科技大学ACM :1005: 一二三
Problem Description 你弟弟刚刚学会写英语的一(one).二(two)和三(three).他在纸上写了好些一二三,可惜有些字母写错了.已知每个单词最多有一个字母写错了(单词长度肯定不 ...
- Java之简单的聊天工具
今天整理资料的时候,找出自己几年前刚学Java时做过的一个简易的聊天工具,有服务器也有客户端,能发送文字消息和文件,但是用户上线并未存入数据库,而只是简单的缓存在服务器的一个数组中,所以,只要服务器一 ...
- 标准SQL语言的用法
原文链接:http://www.ifyao.com/2015/05/18/%E6%A0%87%E5%87%86%E7%9A%84sql%E8%AF%AD%E8%A8%80%E4%BD%BF%E7%94 ...
- PHPCMS V9 如何启用伪静态
最近在研究CMS时候,首先是使用DEDECMS,后来又转到了PHPCMS,感觉后者架构更加合理,而前者主要是模板众多,故使用者多一些,不过我都是需要自己写模板,那就无所谓了. 玩各种CMS我喜欢首先看 ...
- php单词里的大写字母
$flag = preg_match("/[A-Z]/","abcDddd",$matches,PREG_OFFSET_CAPTURE);if($flag){ ...
- Microsoft Anti-Cross Site Scripting Library V4.2 下载地址
概述 微软反跨站脚本库V4.2(AntiXSS V4.2)是一种编码库,旨在帮助开发人员保护他们的ASP.NET基于Web的应用程序免受XSS攻击.它不同于编码库,因为它使用的白名单技术-有时也被称为 ...