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. 寒假挑战PythonTip(一人一python)总结——算法是程序的灵魂,程序员的心法

        2014年2月中旬,我上升到挑战python英雄榜第3名.这是我寒假修炼算法的成果之一.来一下总结吧! Linux的创始人Linus Torvalds在一次演讲中有一段涉及“什么才是优秀程序员 ...

  2. 【面霸1】php知识点

    PHP简介 Hypertext Preprocessor,超文本预处理器的缩写,主要是用于服务端的脚本程序 PHP 标记风格 1.xml风格   < ? php ? > 2.脚本风格  & ...

  3. javascript深入理解js闭包[转]

    一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量 ...

  4. 开发DZ插件教程

    插件制作的基本思路是:(初学者适用)1.形成插件思路2.制作插件界面3.构架程序模块4.搭建存储数据5.填充功能语句6.检查应用错误7.完善插件功能 前言:为方便互联网数万Discuz!爱好者,更加深 ...

  5. windows server 2008 asp连接数据库sql2000失败

    由于服务器现在的服务器已不能承受了,需要替换服务器并把window2003升级为window2008,把所有数据都平移过来.平移完后遇到ASP总是不能连接上sql2000,这让我非常郁闷,处理了好几个 ...

  6. CodeChef FNCS

    题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...

  7. Unity3d 跑酷游戏 之Character Controller篇

    unity3d  Character Controller @by  广州小龙 做3D跑酷游戏,也慢慢的学习了一些东西,从开发过程中积累了一些小的知识点跟大家分享一下! 1. 这个Revert按钮的意 ...

  8. AltiumDesigner导入AutoCAD文件DXF,DWG格式

    最近有个朋友给了个AutoCAD的文件,需要我画个板子,结构什么的参见AutoCAD的文件,百度了下,得知protel是可以导入AutoCAD的DXF,DWG格式的文件的,那么AltiumDesign ...

  9. Linux kernel ‘ip6_sk_dst_check’函数拒绝服务漏洞

    漏洞名称: Linux kernel ‘ip6_sk_dst_check’函数拒绝服务漏洞 CNNVD编号: CNNVD-201307-070 发布时间: 2013-07-05 更新时间: 2013- ...

  10. 搜索(四分树):BZOJ 4513 [SDOI2016 Round1] 储能表

    4513: [Sdoi2016]储能表 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 395  Solved: 213[Submit][Status] ...