[Angular 2] Template property syntax
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.
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的更多相关文章
- [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 ...
- [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 ...
- ASP.NET Core + Angular 2 Template for Visual Studio
多个月以来,我和多个Github上的社区贡献者一起建立支持库.包,我们最终的目的是希望完成这样一个作为起点的模板,也就是基于把Typescript代码和Angular2宿主在ASP.NET Core项 ...
- [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' ...
- [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 ...
- Exploring the Angular 1.5 .component() method
Angular 1.5 introduced the .component() helper method, which is much simpler than the.directive() de ...
- 来自 Thoughtram 的 Angular 2 系列资料
Angular 2 已经正式 Release 了,Thoughtram 已经发布了一系列的文档,对 Angular 2 的各个方面进行深入的阐释和说明. 我计划逐渐将这个系列翻译出来,以便对大家学习 ...
- Angular概念纵览
Conceptual Overview Template(模板): HTML with additional markup (就是增加了新的标记的HTML) Directive(指令): extend ...
- ES6 Syntax and Feature Overview
View on GitHub Note: A commonly accepted practice is to use const except in cases of loops and reass ...
随机推荐
- mysql基础操作整理(一)
显示当前数据库 mysql> select database(); +------------+ | database() | +------------+ | test | +-------- ...
- Transpose File
Given a text file file.txt, transpose its content. You may assume that each row has the same number ...
- 再说CSS3渐变——线性渐变
渐变背景一直以来在Web页面中都是一种常见的视觉元素.但一直以来,Web设计师都是通过图形软件设计这些渐变效果,然后以图片形式或者背景图片的形式运用到页面中.Web页面上实现的效果,仅从页面的视觉效果 ...
- Python入门,新手之路
1.开始使用Python: 从上一篇中我们提到了第一个Python,print("Hello World!")程序说起,看到这一句话,你有没有想过如果括号中的语句不是Hello W ...
- odoo view field option, action flage 参数
options JSON object specifying configuration option for the field's widget (including default widget ...
- WEB可用性、可访问性、可维护性
可用性 (Usability) 可用性是一个多因素概念,涉及到容易学习.容易使用.系统的有效性.用户满意度,以及把这些因素与实际使用环境联系在一起针对特定目标的评价. 可访问性 (Accessibil ...
- smali文件语法参考
Dalvik opcodes Author: Gabor Paller Vx values in the table denote a Dalvik register. Depending on th ...
- 练习2 D 题- 第几天?
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 给定一个日 ...
- DotNet 资源
DotNet 资源 目录 API 应用框架(Application Frameworks) 应用模板(Application Templates) 人工智能(Artificial Intelligen ...
- python中xrange与range的异同
转载自:http://ciniao.me/article.php?id=17 >>> range(5) [0, 1, 2, 3, 4] >>> range(1, 5 ...