Reputation: 895
I was browsing the Angular docs and I came across the FormController class. I see that there are a couple of methods for adding controls and removing them, namely $addControl()
and $removeControl()
. I assume these will be used for dynamically adding and removing form controls, but how exactly do I go about using them?
Upvotes: 2
Views: 2835
Reputation: 49590
formController
tracks a set of child input controls in it for the purposes of setting the controllers of these child input controls on the scope, and of tracking the $dirty
/$pristine
, $valid
/$invalid
, etc... status of the form based its child controls.
This API is called by ngModelController
- which is how Angular implements its built-in (and provides hooks for custom) input controls and by formController
- of sub-forms to register themselves with their parent formController
.
If you implement custom input controllers that require: "ngModel"
(i.e. custom input controls that support the ngModel
abstraction layer), then this is done for you.
And for the vast majority of cases, this is sufficient. But, presumably, one could implement their own ngModel
-like directive, then this API could be used to register the non-ngModel
control with a formController
.
Upvotes: 2