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. Grunt:多个css,js,进行单独压缩

    module.exports = function (grunt) { // 构建任务配置 grunt.initConfig({ //读取package.json的内容,形成个json数据 pkg: ...

  2. LGDT/LIDT-加载全局/中断描述符表寄存器

    将源操作数中的值加载到全局描述符表寄存器 (GDTR) 或中断描述符表寄存器 (IDTR).源操作数指定 6 字节内存位置,它包含全局描述符表 (GDT) 或中断描述符表 (IDT) 的基址(线性地址 ...

  3. [C#]获取最近在Windows上所使用的文件

    class RecentlyFileHelper { public static string GetShortcutTargetFile(string shortcutFilename) { var ...

  4. php之分页类代码

    /* 思路 1.把地址栏的URL获取 2.分析URL中的query部分--就是?后面传参数的部分 3.query部分分析成数组 4.把数组中的page单元,+1,-1,形成2个新的数组 5.再把新数组 ...

  5. 判断JS类型

    (function (root, factory) { if (typeof define === 'function' && define.amd) { define([], fac ...

  6. discuz二次开发技巧

    discuz二次开发技巧 二次开发大多时候知识设置和处理,如果能够获知模板文件获得的变量数组将大大提高我们的开发效率 获取页面已经定义的变量 <--{eval printf_r(get_defi ...

  7. SharePoint 设置Lookup 字段的值

    如何设置Lookup字段的值, 首先我们同样需要了解SPFieldLookupValueCollection和SPFieldLookupValue, 这2个类的原理和之前所讲解到SPFieldUser ...

  8. 转:.NET中使用Redis (一)

    原文来自于:http://blog.jobbole.com/83821/ 原文出处: 寒江独钓   欢迎分享原创到伯乐头条 Redis是一个用的比较广泛的Key/Value的内存数据库,新浪微博.Gi ...

  9. BZOJ 1033 杀蚂蚁

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...

  10. KeilC51使用详解 (一)

    第一节 系统概述 Keil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上.结构性.可读性.可维护性上有明显的优势,因而易学易用.用过 ...