reactive-forms

Angular 2 - Can't set form array value

大兔子大兔子 提交于 2019-12-04 03:18:51
I get this error: There are no form controls registered with this array yet. If you're using ngModel, you may want to check next tick (e.g. use setTimeout). When using this code: public settingsForm: FormGroup = this.fb.group({ collaborators: this.fb.array([]), rsvp: this.fb.group({ latestDate: ['', [Validators.required]], latestTime: ['', [Validators.required]], guestLimit: ['', [Validators.required]], isRSVPOpen: false, isGuestPlusOne: false, isAutoApproveToGuestlist: false, isOnlyFacebookRSVP: false, isBirthdayAndPhoneRequired: false }), tickets: this.fb.group({ info: this.fb.group({

Angular2 reactive form containing a list

烂漫一生 提交于 2019-12-03 12:34:00
I am attempting to create a form for a user that will allow one to may phone numbers to be associated with the user. Is this possible with the current implementation of reactive forms? For example, I would want the below form to accept potentially many phone numbers. My front end implementation would show the phone number field, and would have a button that would allow for an additional phone number field to be added. userForm = new FormGroup({ firstName: new FormControl('', Validators.required), lastName: new FormControl('', Validators.required), phoneNumber: new FormControl('', Validators

Angular forms - access FormArray in child component template

若如初见. 提交于 2019-12-02 10:41:47
问题 I have a component that takes several FormControl s and FormArray s as inputs. I'm accessing the FormControl s from the child component like this: [formControl]="control" This works fine, but I can't find a way to do the same with a FormArray . There doesn't appear to be a directive for it. I would like to avoid passing in a bunch of strings and accessing via formControlName and formArrayName if possible. Is there a way to do this? 回答1: Update there was a type error, jsut corrected You can

Enable When Checkbox is Check in Reactive Forms

旧城冷巷雨未停 提交于 2019-11-28 14:18:16
I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Here's the link to my code LINK CODES patchValues() { let rows = this.myForm.get('rows') as FormArray; this.orders.forEach(material => { material.materials.forEach(x => { rows.push(this.fb.group({ checkbox_value: [null], material_id: new FormControl({value: x.id, disabled: true}, Validators.required), material_name: x.name, quantity: [null, Validators.required] })) }) }) } Have a look at the Demo & Src Stack Blitz, Fork

Enable When Checkbox is Check in Reactive Forms

放肆的年华 提交于 2019-11-27 08:24:08
问题 I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Here's the link to my code LINK CODES patchValues() { let rows = this.myForm.get('rows') as FormArray; this.orders.forEach(material => { material.materials.forEach(x => { rows.push(this.fb.group({ checkbox_value: [null], material_id: new FormControl({value: x.id, disabled: true}, Validators.required), material_name: x.name,