formgroups

Angular Reactive Form with dynamic fields

孤街醉人 提交于 2020-07-23 07:35:16
问题 I'm currently battling with Angular form array. I have a form in which I add the fields dynamically. I have created the form object: this.otherDataForm = this.fb.group({ }); I add the dynamic fields like this: addField(field: CustomFormField): void { this.otherDataForm.addControl(id_campo, new FormControl('', Validators.required)); } I loop through those fields: <form *ngIf="selectedProfile" [formGroup]="otherDataForm"> <div class="mb-3" *ngFor="let field of fields; let i = index"> <label>{

Angular Reactive Form with dynamic fields

…衆ロ難τιáo~ 提交于 2020-07-23 07:33:07
问题 I'm currently battling with Angular form array. I have a form in which I add the fields dynamically. I have created the form object: this.otherDataForm = this.fb.group({ }); I add the dynamic fields like this: addField(field: CustomFormField): void { this.otherDataForm.addControl(id_campo, new FormControl('', Validators.required)); } I loop through those fields: <form *ngIf="selectedProfile" [formGroup]="otherDataForm"> <div class="mb-3" *ngFor="let field of fields; let i = index"> <label>{

Angular 9 How to generate reactive form controls automatically from indexes extracted from an array of data?

允我心安 提交于 2020-06-28 03:58:10
问题 I am trying to create a reactive form from indexes extracted from an array of data. Lets say I have the following array: array = [ { name: 'Ali', gender: 'Male' }, { name: 'Sara', gender: 'Female' } ]; I extracted the index as following: this.result = new Set(this.array.flatMap(e => Object.keys(e), [])); this.result = Array.from(this.result); And the result: console.log(this.result) // ["name", "gender"] Now I need to loop over this.result and create 2 form control names with formControlName=

Angular FormArray: Cannot find control with path

青春壹個敷衍的年華 提交于 2020-06-25 09:12:20
问题 I trying to build an Angular Reactive form where an account can add many students. The form seems to work. When you hit Add Student it creates a new student but you check the console it says ERROR Error: Cannot find control with path: 'studentsArray -> 1 -> firstName and so on for each control in the array. app.component.html <form [formGroup]="accountForm"> <div> <input formControlName="firstName" placeholder="First name"> </div> <div> <input formControlName="lastName" placeholder="Last name

Angular FormArray: Cannot find control with path

泪湿孤枕 提交于 2020-06-25 09:11:09
问题 I trying to build an Angular Reactive form where an account can add many students. The form seems to work. When you hit Add Student it creates a new student but you check the console it says ERROR Error: Cannot find control with path: 'studentsArray -> 1 -> firstName and so on for each control in the array. app.component.html <form [formGroup]="accountForm"> <div> <input formControlName="firstName" placeholder="First name"> </div> <div> <input formControlName="lastName" placeholder="Last name

set value of input based on the dropdown selected using formControlName - ReactiveForms

蹲街弑〆低调 提交于 2020-04-17 22:09:41
问题 I have an input whose value should be based on dropdown selected. here is my code <div class="col-sm-9"> <nb-select type="number" fullWidth id="service" formControlName="service"> <nb-option *ngFor="let service of Services" [value]="service">{{service.name}} </nb-option> </nb-select> </div> <input type="number value="service.price"> My .ts file Services: Array<any>=[ {name: 'Consultation', price: 100}, {name: 'Follow Up', price: 200}, {name: '24 Hrs. Creatinine', price: 300}, {name: 'Complete

set value of input based on the dropdown selected using formControlName - ReactiveForms

狂风中的少年 提交于 2020-04-17 22:07:57
问题 I have an input whose value should be based on dropdown selected. here is my code <div class="col-sm-9"> <nb-select type="number" fullWidth id="service" formControlName="service"> <nb-option *ngFor="let service of Services" [value]="service">{{service.name}} </nb-option> </nb-select> </div> <input type="number value="service.price"> My .ts file Services: Array<any>=[ {name: 'Consultation', price: 100}, {name: 'Follow Up', price: 200}, {name: '24 Hrs. Creatinine', price: 300}, {name: 'Complete

FormControl validator result in TypeError cannot read property of undefined

蓝咒 提交于 2020-03-25 17:56:07
问题 My users are allowed to enter only specific values to an input of text type. Here is the app.component.ts: export class AppComponent implements OnInit { myForm: FormGroup; allowedValuesArray = ['Foo', 'Boo']; ngOnInit() { this.myForm = new FormGroup({ 'foo': new FormControl(null, [this.allowedValues]) }); } allowedValues(control: FormControl): {[s: string]: boolean} { if (!this.allowedValuesArray.indexOf(control.value)) { return {'notValidFoo': true}; } return {'notValidFoo': false}; } } The

how to add nested forms in angular2

蓝咒 提交于 2019-12-24 02:15:23
问题 Image contains problem I have created a form and it is adding rows dynamically from add button but i have also created a button from which i need to add only some components from that link.Add more link button is used to create only those two components. i have used nested form approach, dynamic form approach but not able to do the same. Help needed. HTML:- <div class="container"> <p> </p> <div> <form [formGroup]="searchForm" novalidate (ngSubmit)="submit(searchForm.value)"> <div

disable FormGroup by using Validators

早过忘川 提交于 2019-12-20 05:42:07
问题 I had formArray checkbox on my checkboxForm , I need to disabled button submit if no checkbox are checked , I had implement custom validator on my checkboxForm , this is what I had tried; Ts file get formReceivedSummons() { return this.checkboxForm.get('receivedSummons') as FormArray; } ngOnInit() { this.checkboxForm = this.formBuilder.group({ receivedSummons: this.formBuilder.array([]) }); this.getReceivedSummons(); } getReceivedSummons() { this.receivedSummonsSubscription = this