Reputation: 15064
I am new to Angular2 , While going through blogs on Angular2 , I have come across NgModel
and ngModel
.
I understand that [(ngModel)]
is used for two way binding.
Can any one explain whats the difference between the two?
Upvotes: 2
Views: 357
Reputation: 657476
NgModel
is the class that implements the ngModel
directive.
ngModel
is the selector of that directive.
This means in HTML you use ngModel
like
<input [(ngModel)]="someProp">
but if you need to inject it (for example for a ControlValueAccessor
) you inject a class instance
constructor(private ngModel:NgModel) {}
where ngModel
is just a variable name I choose and NgModel
is the class where we want an instance get injected.
The source shows that because of exportAs: 'ngModel'
it can be used like
<input [(ngModel)]="someProp" let-xxx="ngModel">
{{xxx.name}}
for example to output the name
property (or any other property) of the NgModel
instance that was applied to our <input>
.
Upvotes: 1