formarray

How to get index of changed item in angular form array

﹥>﹥吖頭↗ 提交于 2019-12-02 23:01:20
I'm using Angular 4 with reactive forms. I have a form array that I am trying to tie to an array I keep track of in my component. I'm using reactive forms so I can have the validation, so I don't want to use the template forms approach. I add items to the form array like so: createFormWithModel() { this.orderForm = this.fb.group({ orderNumber: [this.order.ProductBookingOrder], orderDate: [this.order.PurchaseOrderIssuedDate], lineDetailsArray: this.fb.array([]) }) const arrayControl = <FormArray>this.orderForm.controls['lineDetailsArray']; this.order.ProductBookingDetails.forEach(item => { let

Reactive Forms: How to add new FormGroup or FormArray into an existing FormGroup at a later point in time in Angular 7

∥☆過路亽.° 提交于 2019-11-27 05:30:21
In the other examples at StackOverflow there are many questions about using FormGroups in FormArrays. But my question is the opposite. FormArrays have a push method, that makes many things possible. FormGroups have indeed an addControl method for adding simple FormControls. Afaik FormGroups do not have addFormArray or addFormGroup method. Therefore I need your help. Following situation: this.myForm = this.fb.group({ id: this.fb.control([this.book.id]), // or short form `id: [this.book.id],` }); Adding a simple control at a later point in time is easy: this.myForm.addControl('isbn', this.fb

Angular Reactive Forms with nested Form Arrays

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 03:13:46
I'm new to Angular 2 and decided the best way to learn would be to go through the official Angular guides. I went through the Reactive Forms Guide https://angular.io/guide/reactive-forms demo link: https://stackblitz.com/angular/jammvmbrpxle While the content was overall pretty good, I'm stuck on how I would go about implementing a more complex Form. In the given example, each Hero has the potential for many addresses. An address itself is a flat object. What if Addresses had additional information such as the color and type of rooms located at the address. export class Address { street = '';

Reactive Forms: How to add new FormGroup or FormArray into an existing FormGroup at a later point in time in Angular 7

旧巷老猫 提交于 2019-11-26 11:36:01
问题 In the other examples at StackOverflow there are many questions about using FormGroups in FormArrays. But my question is the opposite. FormArrays have a push method, that makes many things possible. FormGroups have indeed an addControl method for adding simple FormControls. Afaik FormGroups do not have addFormArray or addFormGroup method. Therefore I need your help. Following situation: this.myForm = this.fb.group({ id: this.fb.control([this.book.id]), // or short form `id: [this.book.id],` }

Angular Reactive Forms with nested Form Arrays

浪子不回头ぞ 提交于 2019-11-26 10:16:48
问题 I\'m new to Angular 2 and decided the best way to learn would be to go through the official Angular guides. I went through the Reactive Forms Guide https://angular.io/guide/reactive-forms demo link: https://stackblitz.com/angular/jammvmbrpxle While the content was overall pretty good, I\'m stuck on how I would go about implementing a more complex Form. In the given example, each Hero has the potential for many addresses. An address itself is a flat object. What if Addresses had additional