[Angular 2] Using ng-model for two-way binding
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Angular 2] Using ng-model for two-way binding相关的知识,希望对你有一定的参考价值。
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} from ‘angular2/core‘; import {TodoService} from ‘./TodoService‘; @Component({ selector: ‘todo-input‘, template: ` <form (submit)="onSubmit()"> <input type="text" [(ngModel)]="todoModule"> </form> ` }) export class TodoInput{ todoModule: string; constructor(public todoService: TodoService){ } onSubmit(){ this.todoService.todos.push(this.todoModule); console.log(this.todoService.todos); } }
以上是关于[Angular 2] Using ng-model for two-way binding的主要内容,如果未能解决你的问题,请参考以下文章
[Angular 2] Using Promise to Http
[Angular 2] Using ng-model for two-way binding
[Angular 2] Using ng-for to repeat template elements