[Angular 2] Using ng-model for two-way binding
Angular for Using model two NG Binding way
2023-09-14 09:00:54 时间
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); } }
相关文章
- [Unit Testing Angular] RxJS Marble testing for Component
- [Angular 9 Unit testing] Stronger typing for dependency injection in tests
- [Angular] Show a Loading Indicator for Lazy Routes in Angular
- [Angular] 'providedIn' for service
- [Angular] Design API for show / hide components based on Auth
- [Angular] Create custom validators for formControl and formGroup
- [Angular] ChangeDetection -- onPush
- [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State
- [AngualrJS] Using Angular-Cache for caching http request
- [AngularJS] Angular 1.3 $submitted for Form in Angular
- [AngularJS] Using the LocalForage library for offline storage with Angular
- [Angular] Dynamic replacement for index.html
- [Angular] 'providedIn' for service
- [Angular2 Form] Build Select Dropdowns for Angular 2 Forms
- [AngularJS] Test an Angular Component with $componentController
- [AngualrJS] Using Angular-Cache for caching http request
- [Immutable + AngularJS] Use Immutable .List() for Angular array
- [Angular-Scaled web] 5. ui-router $stateParams for sharing information
- [AngularJS] Using the LocalForage library for offline storage with Angular