angular-reactive-forms

Reactive Form - Input field focus out automatically - Angular

泪湿孤枕 提交于 2019-12-24 07:26:02
问题 I am having strange issue. Demo .ts import { Component } from '@angular/core'; import { FormGroup, FormBuilder } from '@angular/forms'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { myForm: FormGroup; constructor(private formBuilder: FormBuilder) {} ngOnInit() { this.myForm = this.formBuilder.group({ 'options': this.formBuilder.array([this.createOption()]) }); } createOption(): FormGroup { return this

Angular : How to access the value of controls in nested forms

天涯浪子 提交于 2019-12-24 04:31:18
问题 I am trying to print get the value of Form Controls of Nested form on Console as well as in HTML. userForm = new FormGroup({ name: new FormControl("Tom Alter"), address: new FormGroup({ Country: new FormControl("India"), State: new FormControl("Delhi") }) }); In Both the cases, I am able to find the value using get statement. console.log ("name : ", this.userForm.controls.name.value); console.log ("Country using Get Way 1 : ", this.userForm.get(['address', 'Country']).value) ; console.log (

Form element values as JSON using angular form

若如初见. 提交于 2019-12-24 01:07:26
问题 I am making angular 6 application where i am using Angular dynamic form Here i have made a nested input fields in which there will be two input textboxes at the initial stage and on click the add button the next two input boxes will get append on each click on add button. Everything works fine here regarding it.. Here i have used the values in question-service.ts as, new TextboxQuestion({ elementType: "textbox", class: "col-12 col-md-4 col-sm-12", key: "project_name", label: "Project Name",

Unique item name validator in Angular FormArray

只愿长相守 提交于 2019-12-23 20:03:59
问题 I want validate the item name text must be unique. I have refered SO links, but links examples are not working for me. I tried to comment on respective answer, but I don't have a much reputation to do that. Link 1: Angular - Uniqueness validator in FormArray Link 2 : Unique value validation in FormControl of FormArray below is my current code: import { Component,OnInit } from '@angular/core'; import { FormGroup,FormBuilder,FormArray } from "@angular/forms" import { RxwebValidators } from "

Angular 5 + Angular Material Select + Reactive Forms == No initial options displayed

大城市里の小女人 提交于 2019-12-23 09:33:00
问题 As the title says, I have a reactive form that has multiple <mat-select> contained within. On initial form load, the initial option is not displayed even though form.value shows it is. Pertinent component.ts: export class DesJobInfoEditComponent implements OnInit { ... currentJobData: IJob; jobTypes: IJobType[]; ... constructor(private fb: FormBuilder) { ... // Construct forms this.createForm(); this.initializeForm(); } createForm() { this.editJobInfoForm = this.fb.group({ ... JobType: '', //

Set reactive form after data loaded (async) - Angular 5

℡╲_俬逩灬. 提交于 2019-12-23 08:01:57
问题 I am trying to update the form values after loading values from an API. I tried using the *ngIf technique but the form is not visible even when the form is set. I am not able to share the full project, but here is the component template and controller Template <div class="page-title"> <h3> Edit news </h3> </div> <div class="partner-add-form"> <ng-container *ngIf='newsForm'> <form action="" [formGroup]='newsForm' (ngSubmit)="onSubmit()"> <div class="row "> <div class="input-field col s12

Create inputs as array in angular form

寵の児 提交于 2019-12-23 05:13:12
问题 Tried my level best please help me out.. I am making an angular dynamic form with a form splitting into total of three parts in which the two parts were made already. Now I am making part three which will be generated by selecting an option from dropdown... Even those part also is done... But I am unable to make a form array in it... As I am new in angular please help me. HTML: Form part 3 will be here which will be array <select multiple (change)="changeEvent($event)"> <option *ngFor="let

Angular PrimeNG dropdown component in reactive forms - initial value

守給你的承諾、 提交于 2019-12-23 01:57:12
问题 using primeNg dropdown component, I'm trying to initialized the dropdown with initial value with no success, I'm using reactive approach. I checked the primeNg documentation and demos - almost all the examples there are using template driven, I would like to have the same with model driven. I'm able to render the dropdown with the values in the list but the selected item is not the one I declared in the form, instead it's the first item in the list. my code: template <div [formGroup]=

FormGroup containing Radio Buttons with an Angular FormArray

跟風遠走 提交于 2019-12-22 18:22:06
问题 I have the following code that dynamically adds a form group containing a title and two radio buttons to create a condition, effectively providing its title and whether or not it's an acceptable condition: export enum Acceptability { ACCEPTABLE, INACCEPTABLE } export interface Condition { title: string; acceptability: Acceptability; } export class AddCondition implements OnInit { form: FormGroup; ACCEPTABILITY = Acceptability; constructor(private fb: FormBuilder) {} ngOnInit() { // build the

Deep copy of Angular Reactive Form?

巧了我就是萌 提交于 2019-12-22 10:59:24
问题 I'm trying to build a function that will produce a copy of a given FormGroup . I started with: function copyForm(form: FormGroup): FormGroup { const copy = new FormGroup({}); for (let key of Object.keys(form.value)) { const control = form.controls[key]; /* Copy the data from the control into a new control */ const copyControl = new FormControl({[key]: control.value}); copy.addControl(key, copyControl); } But that doesn't work if there is a FormArray or FormGroup . This one might work if it