Reputation: 1143
When building a custom form input directive should i use ng-model or my own custom my-val attribute.
The outcome I want is 2 way binding so that changing the input updates the model on the $scope and changing the $scope updates the form input.
I understand that if I "require": "ngModel" in my directive then I get passed the ngModelController whereas using myVal will be a simple property.
Upvotes: 1
Views: 159
Reputation: 49620
The ng-model
serves two main purposes:
form
directive to set $dirty
/$pristine
and $valid
/$invalid
flagsSo, you could definitely have a custom two-way bound attribute, but then you lose out on using directives like ng-required
or ng-change
, and other custom directives that support ng-model
model.
Upvotes: 1