Besides @Input(), we can also use properties on the @Component, to pass the data.

import {Component, View, NgFor, Input} from 'angular2/angular2';

@Component({
selector: 'reddit-article'
})
@View({
directives: [],
template: `
<article>
<div class="votes">{{article.votes}}</div>
<div class="main">
<h2>
<a href="{{article.link}}">{{article.title}}</a>
<span>({{ article.domain() }})</span>
</h2>
<ul>
<li><a href (click)="article.voteUp()">Up</a></li>
<li><a href (click)="article.voteDown()">Down</a></li>
</ul>
</div>
</article>
`
}) export class RedditArticle {
@Input() article: Article; voteUp() {
this.article.voteUp();
return false;
} voteDown() {
this.article.voteDown();
return false;
}
}

Works the same as:

import {Component, View, NgFor, Input} from 'angular2/angular2';

@Component({
selector: 'reddit-article',
properties: ['article'] })
@View({
directives: [],
template: `
<article>
<div class="votes">{{article.votes}}</div>
<div class="main">
<h2>
<a href="{{article.link}}">{{article.title}}</a>
<span>({{ article.domain() }})</span>
</h2>
<ul>
<li><a href (click)="article.voteUp()">Up</a></li>
<li><a href (click)="article.voteDown()">Down</a></li>
</ul>
</div>
</article>
`
}) export class RedditArticle {
article: Article; voteUp() {
this.article.voteUp();
return false;
} voteDown() {
this.article.voteDown();
return false;
}

[Angular 2] Passing data to components with 'properties'的更多相关文章

  1. [Angular 2] Passing data to components with @Input

    @Input allows you to pass data into your controller and templates through html and defining custom p ...

  2. [Angular 2] Passing Observables into Components with Async Pipe

    The components inside of your container components can easily accept Observables. You simply define ...

  3. angular-ui-router state.go not passing data to $stateParams

    app.js中定义了一个state如下,url接收一个id参数 $stateProvider.state("page.details", { url: "/details ...

  4. 问题-Error creating object. Please verify that the Microsoft Data Access Components 2.1(or later) have been properly installed.

    问题现象:软件在启动时报如下错误信息:Exception Exception in module zhujiangguanjia.exe at 001da37f. Error creating obj ...

  5. Windows 的 Oracle Data Access Components (ODAC)

     下载 x64bit https://www.oracle.com/technetwork/cn/database/windows/downloads/index.html 适用于 Windows 的 ...

  6. WIN7系统 64位出现 Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).

    WIN7系统 64位出现  Net Framework 数据提供程序要求 Microsoft Data Access Components(MDAC).请安装 Microsoft Data Acces ...

  7. [转]Passing data between pages in JQuery Mobile mobile.changePage

    本文转自:http://ramkulkarni.com/blog/passing-data-between-pages-in-jquery-mobile/ I am working on a JQue ...

  8. AngularJS - Passing data between pages

    You need to create a service to be able to share data between controllers. app.factory('myService', ...

  9. [Angular2 Router] Use Params from Angular 2 Routes Inside of Components

    Angular 2’s ActivatedRoute allows you to get the details of the current route into your components. ...

随机推荐

  1. 【实习记】2014-08-10(上)代码跟踪git的想法+归并排序的debug过程

        (冒泡,选择,插入,希尔,快速,归并,堆排)周末加班学习C++,打算用C++写七大经典排序代码.发现3个月前自己写的七大经典排序代码(C Language)突然运行出错. Makefile内容 ...

  2. 永久关闭防火墙和selinux

    临时关闭selinux: setenforce 0    //设置SELinux 成为permissive模式 彻底禁用selinux: 使用root用户,vim /etc/sysconfig/sel ...

  3. Overloads和Overrides在元属性继承上的特性

    元属性继承可以使用IsDefined函数进行判断,先写出结论 如果使用Overrides,则元属性可以继承,除非在使用IsDefined时明确不进行继承判断,如 pFunction.IsDefined ...

  4. Django框架学习-Model进阶用法

    Model进阶用法 回顾 访问外键 访问多对多关系 更改数据库结构 当处理数据库结构改变时,需要注意到几点: 增加字段 首先在开发环境中: 再到产品环境中: 删除字段 删除多对多字段 删除model ...

  5. smali文件语法参考

    Dalvik opcodes Author: Gabor Paller Vx values in the table denote a Dalvik register. Depending on th ...

  6. Maya+3dsMax三维建模

    Maya比较擅长动画,在人物和动物的行为活动方面比较擅长 而3ds Max在建筑物地理地图方面比较擅长,多应用于地理 将两者结合起来将会非常有用

  7. Unity问答——怎么知道屏幕中目前有多少个敌人?

    这篇博客源自我在泰课在线的回答.链接:http://www.taikr.com/group/1/thread/92 问:怎么知道屏幕中目前有多少个敌人? 答: 思路一:仅适用于2D游戏,因为这个方法没 ...

  8. h.264直接预测

    直接预测是B帧上一种独有的预测方式,其中直接预测又分为两种模式: 时域直接模式(temporal direct).空域直接模式(spatial direct). 在分析这两种模式之前,有一个前提概念需 ...

  9. Android中SharedPreferences使用方法介绍

    一.Android SharedPreferences的简介 SharedPreferences是一种轻型的Android数据存储方式,它的本质是基于XML文件存储key-value键值对数据,通常用 ...

  10. 转:Mysql读写分离实现的三种方式

    1 程序修改mysql操作类可以参考PHP实现的Mysql读写分离,阿权开始的本项目,以php程序解决此需求.优点:直接和数据库通信,简单快捷的读写分离和随机的方式实现的负载均衡,权限独立分配缺点:自 ...