[Angular 2] Using ng-model for two-way binding
2024-08-26 16:54:32
Two-way binding still exists in Angular 2 and ng-model makes it simple. The syntax is a combination of the [input] and (output) syntax to represent that the data is being pushed out and pulled in.
import {Component, View, FORM_DIRECTIVES} from "angular2/angular2";
import {TodoService} from "./todoService";
@Component({
selector: 'todo-input'
})
@View({
directives: [FORM_DIRECTIVES],
template: `
<form action="" (ng-submit)="onSubmit()">
<input type="text" [(ng-model)]="todoModule">{{todoModule}}
</form>
`
})
export class TodoInput{
todoModule; constructor(
//@Inject(TodoService) todoService
public todoService:TodoService
){
this.todoService = todoService;
console.log(todoService);
} onSubmit(){
this.todoService.addTodo(this.todoModule);
}
}
最新文章
- tornado 学习笔记8 模板以及UI
- nyoj998(euler)
- angularjs如何在视图渲染结束之后,或者render之后执行指令中的link方法呢?
- jquery 小知识点
- CentOS6.5 安装JDK1.7详细步骤参考
- [ Windows] [ OS ] [ Remote Desktop ] 開啟同一個帳號同時2的連線RDP的方式
- 【故障】当Eclipse打不开的时候
- 更改 android realtek的系统权限
- 如何内网搭建NuGet服务器
- 【Java】留下没有基础眼泪的面试题
- 【spring源码分析】IOC容器初始化(二)
- 『Two 树的直径求解及其运用』
- scrollTo不起作用
- Java基于opencv—透视变换矫正图像
- linux 系统备份和恢复
- python之attrgetter函数对对象排序
- java中String类型
- 推荐几个Windows工具软件: Stickies - 桌面贴
- 您的windows许可证即将过期 win10的解决办法
- 微信小程序组件 分页菜单点击请求
热门文章
- printf 格式化最常用用法
- nginx+php,502错误
- 『重构--改善既有代码的设计』读书笔记----Self Encapsulate Field
- sql server 数据分页显示。
- 通过C# 打开一个应用程序
- 在Linux终端执行clear或top命令时出现:&#39;xterm&#39;: unknown terminal type
- Python 环境
- BAE 环境下配置 struts2 + spring + hibernate(SSH)(一)准备
- vim技巧:折叠快捷键
- gcc将多个静态库链接成一个静态库