This lesson covers using the [input] syntax to change an element property such as “hidden” or “content-editable”. Using properties eliminates the need for Angular 1’s old directives such as ng-show and ng-hide as you’re now able to directly access any property on your element.

 todoService.ts

export class TodoModel{
status: string = "started";
constructor(
public title: string = ""
){} toggle(): void{
if(this.status === "started") this.status = "completed";
else this.status = "started";
}
}

todoList.ts

import {Component, View, NgFor} from 'angular2/angular2';
import {TodoService} from './todoService'; @Component({
selector: 'todo-list'
})
@View({
directives: [NgFor],
template: `
<div>
<div *ng-for="#todo of todoService.todos">
<span [content-editable]="todo.status === 'started'">{{todo.title}}</span>
<button (click)="todo.toggle()">Toggle</button>
</div>
</div>
`
}) export class TodoList{
constructor(
public todoService:TodoService
){ }
}

[Angular 2] Template property syntax的更多相关文章

  1. [Angular2 Form] Angular 2 Template Driven Form Custom Validator

    In this tutorial we are going to learn how we can also implement custom form field validation in Ang ...

  2. [Angular 2] Generate and Render Angular 2 Template Elements in a Component

    Angular 2 Components have templates, but you can also create templates inside of your templates usin ...

  3. ASP.NET Core + Angular 2 Template for Visual Studio

    多个月以来,我和多个Github上的社区贡献者一起建立支持库.包,我们最终的目的是希望完成这样一个作为起点的模板,也就是基于把Typescript代码和Angular2宿主在ASP.NET Core项 ...

  4. [Angular] New async 'as' syntax and ngIf.. else

    From Anuglar v4 above, we are able to using 'as' with async pipe. This allow as using 'new variable' ...

  5. [Angular] Create a custom validator for template driven forms in Angular

    User input validation is a core part of creating proper HTML forms. Form validators not only help yo ...

  6. Exploring the Angular 1.5 .component() method

    Angular 1.5 introduced the .component() helper method, which is much simpler than the.directive() de ...

  7. 来自 Thoughtram 的 Angular 2 系列资料

    Angular 2 已经正式 Release 了,Thoughtram 已经发布了一系列的文档,对 Angular 2 的各个方面进行深入的阐释和说明. 我计划逐渐将这个系列翻译出来,以便对大家学习 ...

  8. Angular概念纵览

    Conceptual Overview Template(模板): HTML with additional markup (就是增加了新的标记的HTML) Directive(指令): extend ...

  9. ES6 Syntax and Feature Overview

    View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reass ...

随机推荐

  1. mysql基础操作整理(一)

    显示当前数据库 mysql> select database(); +------------+ | database() | +------------+ | test | +-------- ...

  2. Transpose File

    Given a text file file.txt, transpose its content. You may assume that each row has the same number ...

  3. 再说CSS3渐变——线性渐变

    渐变背景一直以来在Web页面中都是一种常见的视觉元素.但一直以来,Web设计师都是通过图形软件设计这些渐变效果,然后以图片形式或者背景图片的形式运用到页面中.Web页面上实现的效果,仅从页面的视觉效果 ...

  4. Python入门,新手之路

    1.开始使用Python: 从上一篇中我们提到了第一个Python,print("Hello World!")程序说起,看到这一句话,你有没有想过如果括号中的语句不是Hello W ...

  5. odoo view field option, action flage 参数

    options JSON object specifying configuration option for the field's widget (including default widget ...

  6. WEB可用性、可访问性、可维护性

    可用性 (Usability) 可用性是一个多因素概念,涉及到容易学习.容易使用.系统的有效性.用户满意度,以及把这些因素与实际使用环境联系在一起针对特定目标的评价. 可访问性 (Accessibil ...

  7. smali文件语法参考

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

  8. 练习2 D 题- 第几天?

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 给定一个日 ...

  9. DotNet 资源

    DotNet 资源 目录 API 应用框架(Application Frameworks) 应用模板(Application Templates) 人工智能(Artificial Intelligen ...

  10. python中xrange与range的异同

    转载自:http://ciniao.me/article.php?id=17 >>> range(5) [0, 1, 2, 3, 4] >>> range(1, 5 ...