You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using reactive form, a child custom form component is not able to access its parent form in order to add form controls to the parent. When injecting FormGroupDirective, the "form" property is null.
Expected behavior
When injecting FormGroupDirective and the component is part of a reactive form, the "form" property should give a reference to the parent's form.
Minimal reproduction of the problem with instructions
PARENT FORM IS NULL ERROR TypeError: Cannot read property 'addControl' of null
What is the motivation / use case for changing the behavior?
Adding child form to a parent form without requiring the parent form to create form controls for the child form elements.
Environment
Angular version: 6.0.1
Browser:
- [x ] Chrome (desktop) version 66.0.3359.170
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [x ] IE version 11
Others:
The text was updated successfully, but these errors were encountered:
FormGroupDirective.form is set through an input property, so it won't be set yet in the constructor of the nested form component. If you save the directive instead and call this.form.form in your hook, it should work as intended.
I'm submitting a...
Current behavior
This is based on the sub-form demo by @kara for reactive forms: https://youtu.be/CD_t3m2WMM8?t=2130
Using reactive form, a child custom form component is not able to access its parent form in order to add form controls to the parent. When injecting FormGroupDirective, the "form" property is null.
Expected behavior
When injecting FormGroupDirective and the component is part of a reactive form, the "form" property should give a reference to the parent's form.
Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/angular-53qnzx
Examine console:
PARENT FORM IS NULL
ERROR TypeError: Cannot read property 'addControl' of null
What is the motivation / use case for changing the behavior?
Adding child form to a parent form without requiring the parent form to create form controls for the child form elements.
Environment
The text was updated successfully, but these errors were encountered: