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!).
[
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
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)]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With