angular-reactive-forms

Dynamic form array with dynamic options

笑着哭i 提交于 2021-02-05 09:29:39
问题 I want to make a student able to choose several workshops in a dynamic number of school subjects 1.- I have a config array, this array have the number of options of the student will choose for every subject let configarray = {initdate: 2019-07-01, subjectnumber: 4}; In this example for every subject the student will be able to choose 4 options. let b = this.FormGuardar.get("opciontaller") as FormArray; for (let i = 0; i < configarray.subjectnumber; i++) { let preregistro = this._fb.group({

Loop through nested formgroup and change each form control value to null if it has pattern error

坚强是说给别人听的谎言 提交于 2021-02-04 08:26:32
问题 I have to find if one of my formcontrols has a pattern error. If it has a pattern error, then I have to change the value of that formcontrol to null. I wrote a recursive method that calls itself to check if one f the form control has a pattern error and then it finally returns true or false, But what I want is to change the value of that formcontrol to null Here is my recursive function, hasPatternError(form: AbstractControl, isRecursion = false): boolean { if (!isRecursion) { this

get multiple checkbox value as an array in angular

放肆的年华 提交于 2021-02-01 05:17:05
问题 i'm trying to get values from multiple checkbox here https://stackblitz.com/edit/angular-ivy-uahtjx i try this approach but didn't with for me https://stackblitz.com/edit/quiz-answer-value i think it's because the JSON schema is different, first one is array, and the second one is object. i set up my html like this <div *ngFor="let option of form.options"> <label><input (change)="onChange(i,j, form.code,check.checked)" #check [value]="answers[i].value.forms[j].answer.toString().indexOf(form

How to compare array of objects using angular8 using reactive forms

烈酒焚心 提交于 2021-01-29 17:15:35
问题 i have used reactive forms, and the values are getting assigned to the html and the reactive forms is due to the array of object. So, what ever action i perform there must be used for comparing objects with the existing object. So i have used one array of object comparison method. But here the previous value is also getting binded to the new value which has been assigned to the form. I want the newly edited value and the old value as seperate so that i can compare if the object proerty values

Angular Reactive form validation

我是研究僧i 提交于 2021-01-29 14:16:08
问题 I'm working with a Reactive form and I have noticed in some tutorials they do the following: HTML . . <input type="text" formControlName="firstName" required> . . TS . . firstName: ['', Validators.required] . . QUESTION: Why do I need to specify "required" in the HTML if I just do it in the TS file it works fine? 回答1: Actually, Angular mention something about that here: Caution: Use these HTML5 validation attributes in combination with the built-in validators provided by Angular's reactive

Angular Custom focus Directive. Focus a form's first invalid input

萝らか妹 提交于 2021-01-29 11:28:24
问题 I have created a directive to focus an input if it's invalid import { Directive, Input, Renderer2, ElementRef, OnChanges } from '@angular/core'; @Directive({ // tslint:disable-next-line:directive-selector selector: '[focusOnError]' }) export class HighlightDirective implements OnChanges { @Input() submitted: string; constructor(private renderer: Renderer2, private el: ElementRef) { } ngOnChanges(): void { const el = this.renderer.selectRootElement(this.el.nativeElement); if (this.submitted &&

How can we set errors on form array control dynamically on initally page load

北城余情 提交于 2021-01-29 10:33:46
问题 In one of my requirements, I have form an array-like grid table contains rows and columns. once on Init i am doing a service call and get the columns and values and error messages. based on that i have created a form array for that columns and each columns have errormessage if errormessage exists need to set errors. I can able to set value for those columns but not able to set errors while pushing into form array i don't know how could I push error as well. stuck on this line. Qn? On

Created custom radio button library, but did not check radio button while binding with reactive-form

£可爱£侵袭症+ 提交于 2021-01-28 14:13:18
问题 Angular library I am trying to created a library for custom radio button with its role like warning(color yellow dot) error(color red dot) info(color blue dot) and success(color green dot) without angular library it will work fine, After that I move my css and template to library but now it is not work is expected I have provide value from reactive from but it does not check as expect I have also added screenshot at the end what I am expecting and what I get currently radio-button.html <label

Angular 7 and form arrays error of cannot find a control with path

时间秒杀一切 提交于 2021-01-28 11:25:32
问题 I am building a form group with an array inside of it, using mat-table data source. I started by creating the table: <form *ngIf="formGroup" [formGroup]="formGroup"> <table mat-table [dataSource]="dataSource" *ngIf="total>0" formArrayName="distribution"> <ng-container matColumnDef="ind_id"> <th mat-header-cell *matHeaderCellDef> ID </th> <td mat-cell *matCellDef="let element">{{element.individual_id}}</td> </ng-container> <ng-container matColumnDef="ind_name"> <th mat-header-cell

How to calculate value from multiple inputs using angular reactive forms?

谁说我不能喝 提交于 2021-01-28 08:54:38
问题 I'm trying to calculate either discount percent or discount amount from list price using angular 6 reactive forms . form.component.html (simplified) ... <form [formGroup]="productForm"> <mat-form-field class="quat-width"> <span matPrefix>$  </span> <input matInput type="number" name="CostPrice" formControlName="CostPrice"> </mat-form-field> <mat-form-field class="quat-width"> <span matPrefix>$  </span> <input matInput type="number" name="ListPrice" formControlName="ListPrice"> </mat-form