-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(form.FormController): add $getControls() #16601
Conversation
Fixes angular#14749 Closes angular#14517 Closes angular#13202
d198a2d
to
30db7f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM. Just a couple of minor suggestions.
src/ng/directive/form.js
Outdated
@@ -4,6 +4,7 @@ | |||
*/ | |||
var nullFormCtrl = { | |||
$addControl: noop, | |||
$getControls: noop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should return an empty array (to respect the "contract" that $getControls()
returns an array).
Maybe change it to valueFn([])
.
src/ng/directive/form.js
Outdated
* @description | ||
* This method returns a **shallow copy** of the controls that are currently part of this form | ||
* ({@link form.FormController `FormController`} / | ||
* {@link ngModel.NgModelController `NgModelController`}) . This can be used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume here you refer to the fact that the controls can be either FormController
or NgModelController
instances. Having this parenthesis after "of this form" is a little confusing.
I think it makes sense to be more explicit about this in the docs (because not all people might realize controls
can actually be other FormController
s) and also mention that if you want nested controls, you have to recursively call $getControls()
on sub-forms.
b6d0284
to
ab8f14a
Compare
@gkalpak Pr has been updated, PTAL |
test/ng/directive/formSpec.js
Outdated
|
||
scope.$digest(); | ||
|
||
var form = doc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable.
Fixes #14749
Closes #14517
Closes #13202
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feat
What is the current behavior? (You can also link to an open issue here)
there's no straight forward way to get all controls of a form
What is the new behavior (if this is a feature change)?
you can get a shallow copy of the form controls
Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information:
I decided against a synchronized copy (#14749 (comment)) because I don't see the clear benefit over a simple shallow copy + is slightly more involved to implmenent.