angular-reactive-forms

How can I reset Angular Reactive Form

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 04:28:54
I have tried and failed to find the way in which to reset my angular form. Can somebody help? <form #thisIsAForm> <mat-form-field class="full-width"> <input matInput placeholder="Weather"> </mat-form-field> </form> <button mat-raised-button (click)="resetForm()">Reset</button> export class Example{ @ViewChild('thisIsAForm') thisIsAForm; resetForm() { this.thisIsAForm.reset(); } } Almost ! Use a reactive form for that : <form [formGroup]="myForm"> <mat-form-field class="full-width"> <input matInput placeholder="Weather" formControlName="weather"> </mat-form-field> </form> <button mat-raised

Setting Angular 2 FormArray value in ReactiveForm?

心不动则不痛 提交于 2019-12-05 03:36:47
There is already a similar question here ( Setting initial value Angular 2 reactive formarray ) but I am not satisfied with the answer or maybe looking for some other solution. I think whole point of having FormArray is to pass the array of objects and it should create equal number of components. But in this above example if you look at the provided plunker , even after providing two Addresses object one Address was created because its blank version was already created in ngOnInit() . So my question is if in ngOnInit() I have it like this addresses: this._fb.array([]) // blank list, then how

How to make cascading dropdown in a Angular Reactive Formarray work without messing the dropdown value

核能气质少年 提交于 2019-12-05 03:30:23
I have a form in angular 4 that containing First Name + Last Name and a formarray containing 2 dropdown(select) working as cascading dropdown and a delete button. The rest of the form also contains a send button and a add option button. I added a screenshot down here for you to understand better. The forms add , remove button and send button works there is 1 problem the cascading dropdown works only when there is 1 cascading dropdown ,when I add an extra cascading select the value from previous groups of cascading select second select get messed up. I added pics down here for a better

Two way binding on angular 6 reactive form

蹲街弑〆低调 提交于 2019-12-05 01:41:54
I am trying to create a complex reactive form with nested component that is populated with a data object. The behavior I am trying to achieve is very similar to the two-way data binding of a template-driven form: when the user edits an input of the form, the data object is changing automatically . but as opposed to template-driven form, I cannot use [(ngModel)] because it is deprecated in reactive forms for angular V6. I know that fromGroup.patchValue() will only do a one way binding and then ill have to manually subscribe to change events and update the data object manually - this will result

ERROR Missing number at position 0 when using setValue angular 4

风格不统一 提交于 2019-12-05 01:19:36
I'm using Angular 4 with reactiveforms, momentjs , and primeng calendar I'm tying to use setValue and have tried patchValue on a reactiveForm field which contains a Date. This date has been created via a primeng calendar. purchaseDate: Sat Sep 02 2017 00:00:00 GMT+0100 (GMT Daylight Time) I use this 'date' to do a couple of things and then onSumbit of the form I convert the date using momentjs to a clean format ready for the backend to accept (i.e. YYYY.MM.DD) using .moment().format(.... However when I run the .setValue I'm getting the following console error ERROR Missing number at position 0

Angular 4: reactive form control is stuck in pending state with a custom async validator

天涯浪子 提交于 2019-12-05 00:39:24
I am building an Angular 4 app that requires the BriteVerify email validation on form fields in several components. I am trying to implement this validation as a custom async validator that I can use with reactive forms. Currently, I can get the API response, but the control status is stuck in pending state. I get no errors so I am a bit confused. Please tell me what I am doing wrong. Here is my code. Component import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import {

Reactive Angular form to wait for async validator complete on submit

给你一囗甜甜゛ 提交于 2019-12-04 20:27:35
问题 I am building a reactive angular form and I'm trying to find a way to trigger all validators on submit. If the validor is a sync one, it'd be ok, as I can get the status of it inline. Otherwise, if the validator is an async one and it was not triggered yet, the form on ngSubmit method would be in pending status. I've tried to register a subscribe for the form statusChange property, but it's not triggered when I call for validation manualy with markAsTouched function. Here's some snippets: /

Angular 4 Dynamic form with nested groups

ぐ巨炮叔叔 提交于 2019-12-04 14:58:32
I want to generate a reactive form from the tree structure. Here is the code that creates the form items (form groups and controls). For the controls nested in form group it I use a recursive template. import { Component, Input, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; @Component({ selector: 'form-item', template: ` <ng-container [formGroup]="form"> <ng-container *ngTemplateOutlet="formItemTemplate; context:{ $implicit: pathSegments }"></ng

Angular - Reactive Forms - How to pass an object to a FormGroup with a class and validators

不想你离开。 提交于 2019-12-04 12:40:24
I have a large form to create and decided to use the reactive form feature for ease of use. However, I am facing a few challenges that might be obvious and looking for help. Below are two cases that yield the same outcome with the exception of the validation. The createFormWithValidation() method specifics every control and it's associated validators. The createFromPassingObject() method creates the same form using just the this.party object but without the added validators. My goal is to pass an object to this.fb.group() that will have the controls that are part of the class and be able to

Angular 7 select dropdown object is empty when not touched

南笙酒味 提交于 2019-12-04 11:51:26
In my application, ngOnInit() loads currencies, categories, and manufacturers. I am using Angular 7 reactive forms for this. Data loads as expected and dropdowns populated with values and the first option selected and showed to the user. So, here is the problem, after finishing form and clicking on submit (using default dropdown values), I see an empty object for the category , currency , and manufacturer . ProductNewComponent.ts import {Component, OnInit} from '@angular/core'; import {Router} from '@angular/router'; import {ProductService} from '../service/product.service'; import