angular-reactive-forms

How to use formControlName and deal with nested formGroup?

混江龙づ霸主 提交于 2019-12-02 17:31:06
As Angular documentation says we can use formControlName in our forms: <h2>Hero Detail</h2> <h3><i>FormControl in a FormGroup</i></h3> <form [formGroup]="heroForm" novalidate> <div class="form-group"> <label class="center-block">Name: <input class="form-control" formControlName="name"> </label> </div> </form> As they say... Without a parent FormGroup, [formControl]="name" worked earlier because that directive can stand alone, that is, it works without being in a FormGroup. With a parent FormGroup, the name input needs the syntax formControlName=name in order to be associated with the correct

Angular Reactive Form : Cannot set property of undefined

半世苍凉 提交于 2019-12-02 17:21:30
问题 I'm stuck with Angular5 ReactiveForm. Actually, I create a basic model sub sub.model.ts : export interface Subscription { name: string; } I also have a component : : sub.component.ts import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Sub } from '@models/sub.model'; @Component({ selector: 'md-subscribe', templateUrl: './subscribe.component.html', styleUrls: ['./subscribe.component.scss'] }) export class SubComponent

Angular dynamic form nested fields

北城余情 提交于 2019-12-02 12:01:55
With the help of https://angular.io/guide/dynamic-form , i am making a dynamic form where i am in the need to display two fields at first. new TextboxQuestion({ key: 'firstName', label: 'First name', value: '', required: true, order: 1 }), new TextboxQuestion({ key: 'lastName', label: 'Last name', value: '', required: true, order: 2 }), These two fields needs to be at first on loading. After this i will have two buttons as add and remove . <button (click)="addNew()"> Add </button>     <button (click)="removeNew()"> Remove </button> <br><br> By clicking add, i need to display the next two

Change form elements using angular form

落花浮王杯 提交于 2019-12-02 12:01:02
I am making angular dynamic form with form-elements loaded through JSON.. The form element generation are working fine, but i am in the need of change of form elements based on options selected from dropdown.. JSON that generates form-elements jsonData: any = [ { "elementType": "textbox", "class": "col-12 col-md-4 col-sm-12", "key": "project_name", "label": "Project Name", "type": "text", "value": "", "required": false, "minlength": 3, "maxlength": 20, "order": 1 }, { "elementType": "dropdown", "key": 'project', "label": 'Choose option to display', "options": [ { "key": 'description', "value":

Angular table row contains sum of columns dynamically using Reactive Forms

孤人 提交于 2019-12-02 08:33:48
i'm working in angular project where i want to show a table with two columns and dynamic row and last row conatins sum of each column when user type any number , this is what i want to achieve : element | FR | EN | ------------------- elem A | | | ------------------- elem B | | | ------------------- elem C | | | ------------------- Total | | | and this is my angular code : componenet.ts : listDecompositionLibelle: string[] = ['elem A', 'elem B','elem C']; ngOnInit() { this.valuesForm = this.fb.group({ decomposition : this.fb.array([ ]) }); for (let i = 0; i < 3; i++) { this

Step wizard form

匆匆过客 提交于 2019-12-02 08:31:52
I am making angular application with angular dynamic form where i need to split up the form into two parts. In which i have input field firstname and lastname at first page and on click the next button the children which has email and dropdown needs to get loaded.. Html: <form (ngSubmit)="onSubmit()" [formGroup]="form"> <div *ngFor="let question of questions" class="form-row"> <ng-container *ngIf="question.children"> <div [formArrayName]="question.key"> <div *ngFor="let item of form.get(question.key).controls; let i=index" [formGroupName]="i"> <div *ngFor="let item of question.children"> <app

What is the best practice to show Reactive Form Error Message without multiple *ngIf?

我与影子孤独终老i 提交于 2019-12-02 07:14:36
I am developing job form which contains job related fields and some of the fields have more than 5 validation. Here is my Html Code: <div [formGroup]="jobForm"> <div> <input type="text" formControlName="userName"/> <div *ngIf="jobForm.controls.userName.errors && jobForm.controls.userName.errors.required" class="alert alert-danger"> Required.... </div> <div *ngIf="jobForm.controls.userName.errors && jobForm.controls.userName.errors.maxLength" class="alert alert-danger"> max length 10 </div> <div *ngIf="jobForm.controls.userName.errors && jobForm.controls.userName.errors.exits" class="alert

Custom Validator Control Quantity in Reactive Forms

 ̄綄美尐妖づ 提交于 2019-12-02 06:46:24
I had a hard time implementing a custom validation in my reactive forms in Angular. I need to control the quantity. The quantity should not be more than the available quantity. The problem how can i get the total of all the quantity if each row has subrows. How will i able to compute the total of subrows and compare it to its parent row where the available quantity is found. Here's my code below. Here's also the link to my code PLEASE CLICK THIS LINK customValidator(campo1: string) { return (group: FormGroup): { [key: string]: any } => { const receive = group.controls[campo1]; //Change this

Searching Data From Different Component in Angular NGXS

ε祈祈猫儿з 提交于 2019-12-02 04:40:18
问题 I'm trying to figure out how will i able to search in NGXS from different component. I have my searchbar from the navbar component while i'm displaying my data from app component which is a different component. Please see this stackblitz link CLICK HERE CODE this.peopleForm.get('name').valueChanges.pipe(debounceTime(500)).subscribe( (name: string) => { console.log(name); this.people$ = this.store.select(AppState.nameFilter(name)); } ) 回答1: Having a look at your StackBlitz, it seems you are

Patch the values in angular form

◇◆丶佛笑我妖孽 提交于 2019-12-02 04:16:59
问题 I am making an application using angular 6, where i am using angular dynamic form. As of creating the form and submitting i have completed everything, You could able to see the working stackblitz , https://stackblitz.com/edit/angular-x4a5b6-hne6fg FYI: This form has children elemts which will gets opened and also gets append on click the add button and removes one by last on click the remove button.. The thing i am in the need is, i just need to patch the values to each inputs via service