-1

[(ngModel)] is two way binding to exchange data from the component to view and from view to the component. [ngModel] is one way binding, but it gave me the same behaviour as [(ngModel)].

with [ngModel], i can get the value from the component and display it in the view, and i can set the value from view to component also. if [ngModel] a one way binding, how can we exchange data between compnent and view like that. I'm really confused about this two annotations.

Another quesion, is ngModel wich is used with ngform a one way binding?

  <input class="form-control" type="text" name="designation" [ngModel]="currentProduct.name"> 

give the same thing as:

<input class="form-control" type="text" name="designation" [(ngModel)]="currentProduct.name"> 
Daniel
  • 45
  • 1
  • 1
  • 9

1 Answers1

1
  1. [ngModel]="currentProduct.name" is the syntax for one-way binding

  2. [(ngModel)]="currentProduct.name" is for two-way binding

So it means that in the 1st syntax you can pass data from your parent component to your child.

And the 2nd syntax you can pass data in the two ways, parent to child and child to parent.

Read more from the angular doc

crg
  • 4,284
  • 2
  • 29
  • 57