Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between ng-model and NgModel in Angular 2?

Tags:

angular

In Angular 2.x, is there a difference between ng-model and NgModel in Angular 2? Referring to following Angular documentation

https://angular.io/docs/ts/latest/guide/architecture.html

It uses terminology [(ng-model)]="property" to explain two-way data binding. Just below this, it uses the example using NgModel (instead of ng-model)

<input [(ngModel)]="hero.name">

I am confused if this is a typo (I guess not!).

like image 806
Manu Chadha Avatar asked Jun 01 '17 05:06

Manu Chadha


2 Answers

[ is component bind to view . ( is view bind to component . ngModel is two way binding so this use this syntax [( . And there is no differentce beetween [(ngModel]) in angular2+ and ng-model in angular1

like image 95
Akashii Avatar answered Nov 15 '22 17:11

Akashii


No, there is no difference, but the one in Angular gives you more flexibility than the one in AngularJS.

[( in Angular is signalling a two-way data binding. Theoretically you could only bind to an event ((ngModel)) or to a value ([ngModel]). This gives you the ability to handle changes going down in a different way than changes coming up. With AngularJS you do not have that flexibility.

But just to sum up, ng-model is equal to [(ngModel)].

like image 42
Vladimir Zdenek Avatar answered Nov 15 '22 15:11

Vladimir Zdenek