Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between using ng-model and ng-control in angular2?

Tags:

angular

 <form role="form" #form="form" (ng-submit)="submit(form.value)">
    <input type="text" placeholder="Enter your name" ng-control="name">
    <input type="text" placeholder="Enter your email" [(ng-model)]="email">
    <button>Submit</button>
  </form>

What is the diff b/w using ng-model and ng-control? When to use each of them?

like image 357
Vikram Babu Nagineni Avatar asked Nov 08 '22 20:11

Vikram Babu Nagineni


1 Answers

ngControl, ngModel and ngFormControl are selectors for NgControlStatus directive, so there's no difference between them...

NgControlStatus is Directive automatically applied to Angular forms that sets CSS classes based on control status (valid/invalid/dirty/etc).

NgFormControl is directive that binds input field in the template to the Control class that is used to programmatically create form fields.

NgFormControl Binds an existing Control to a DOM element.

like image 165
Sasxa Avatar answered Nov 15 '22 07:11

Sasxa