@Input allows you to pass data into your controller and templates through html and defining custom properties. This allows you to easily reuse components, such as item renderers, and have them display different values for each instance of the renderer.

todoItemRender.ts

import {Input, Component, View} from "angular2/angular2";

@Component({
selector: 'todo-item-render'
})
@View({
template: `
<div>
<span [content-editable]="todoinput.status === 'started'">{{todoinput.title}}</span>
<button (click)="todoinput.toggle()">Toggle</button>
</div>
`
}) export class TodoItemRender{
@Input() todoinput: TodoModel;
}

todoList.ts

import {Component, View, NgFor} from 'angular2/angular2';
import {TodoService} from './todoService';
import {TodoItemRender} from './todoItemRender' @Component({
selector: 'todo-list'
})
@View({
directives: [NgFor, TodoItemRender],
template: `
<div>
<todo-item-render
*ng-for="#todo of todoService.todos"
[todoinput]="todo"
>
</todo-item-render>
</div>
`
}) export class TodoList{
constructor(
public todoService:TodoService
){ }
}

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

  1. [Angular 2] Passing data to components with 'properties'

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

  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. [mjpeg @ ...] unable to decode APP fields: Invalid data found when processing input

    通过FFmpeg打开自己笔记本摄像头(HP Wide Vision HD Camera)操作时遇到如下错误: [mjpeg @ 0000029be7cbd000] unable to decode A ...

  9. [Angular 2] Passing Template Input Values to Reducers

    Angular 2 allows you to pass values from inputs simply by referencing them in the template and passi ...

随机推荐

  1. topcoder算法练习3

    SRM144 DIV1 1100 point Problem Statement      NOTE: There are images in the examples section of this ...

  2. 微信公众平台开发(免费云BAE+高效优雅的Python+网站开放的API)

    虽然校园App是个我认为的绝对的好主意,但最近有个也不错的营销+开发的模式出现:微信平台+固定域名服务器. 微信公众平台的运行模式不外两个: 一.机器人模式或称转发模式,将说话内容转发到服务器上完成, ...

  3. 获取IP城市

     新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 多地域测试方法:http://int.dpool.sina. ...

  4. 借助Q.js学习javascript异步编程。

    金字塔式 //add1 function step1(n, callback) { setTimeout(function(){ callback.call(null, n + 1); }, 100) ...

  5. javascript获取div高度

    DOM的: 获得了div的高度值 = document.getElementById("目标id").offsetHeight;

  6. JQUERY 键盘事件

    一 一.首先需要知道的是: 1.keydown()keydown 事件会在键盘按下时触发. 2.keypress()keypress 事件会在敲击按键时触发,我们可以理解为按下并抬起同一个按键. 3. ...

  7. ajax异步请求不能刷新数据的问题

    搞了两三天的问题,今天解决了.总结下: function reportGrpChange(cuid, title){ document.getElementById('reportFrameDiv') ...

  8. Java socket 说明 以及web 出现java.net.SocketException:(Connection reset或者Connectreset by peer:Socket write error)的解释

    另外http://www.cnblogs.com/fengmk2/archive/2007/01/15/using-Socket.html可供参考   一Java socket 说明 所谓socket ...

  9. Surprising Strings(map类)

    http://poj.org/problem?id=3096 题意容易理解,开始直接暴力,还是用map写下吧,熟练一下: #include<stdio.h> #include<str ...

  10. Light OJ 1011 - Marriage Ceremonies(状压DP)

    题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少?   状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...