Questions tagged [angular2-formbuilder]

Questions about Angular FormBuilder, a built-in API for creating instances of a FormControl / FormGroup / or FormArray using less code. Available in @angular/forms package.

Angular FormBuilder is a built-in API in @angular/forms package for creating instances of a FormControl / FormGroup / or FormArray. It reduces the boilerplate code required and allows you to create complex reactive form.

has the following methods.

  • group(): Creates FormGroup.

  • control(): Creates FormControl.

  • array(): Creates FormArray.

Related tags: , , ,

See the official guide for a detailed introduction to FormBuilder.

242 questions
14
votes
2 answers

Angular FormControl valueChanges doesn't work

I want to get one of my forms ("family") value if changed by subscribing but it seems something is wrong because I got nothing on my console's log. import { Component , AfterViewInit } from '@angular/core'; import {FormGroup,FormBuilder} from…
M.J
  • 236
  • 1
  • 2
  • 13
13
votes
5 answers

Form Builder with hasError() for validation throws an error of ERROR TypeError: Cannot read property 'hasError' of undefined

Hi I am implementing a form in angular 2 using Form Builder in component.ts i have implemented my form using formGroup Below is My code public myForm: FormGroup; constructor(private authenticateservice: AuthenticateService, private…
12
votes
2 answers

How to iterate formgroup with array in Angular2

I'm working on a model driven form and I can't get it to add items to a list being displayed with ngFor. I'm currently getting an error when trying to iterate my list. Error: Error: Cannot find control with path: 'locations -> i' at new…
Jason Stokes
  • 647
  • 2
  • 6
  • 20
10
votes
4 answers

Angular 4: setValue formBuilder empty array

I have such reactive form: constructor(...){ this.form = this.formBuilder.group({ name: ['', Validators.compose([Validators.required, Validators.maxLength(50)])], memes: this.formBuilder.array([ this.initMemes('TrollFace') ]) …
brabertaser19
  • 5,384
  • 14
  • 69
  • 164
10
votes
3 answers

Angular 2 form valueChanges fires continuously

I am trying to update the value name of a form with a value I get from a service, once the location field is filled. I try to this by watching the valueChanges of the form object. It works, but it fires continuously, although the values don't change…
ama
  • 1,166
  • 1
  • 12
  • 29
10
votes
2 answers

how to setvalue in formbuilder array

I have a problem about set array value to formBuilder.array. In the formBuilder that not array it can use this way to setValue but in formBuilder.array I can't do it. I try set value to formbuilder 'listServiceFeature' and 'listservicefeature' but…
Mahalo Bankupu
  • 272
  • 3
  • 4
  • 17
10
votes
2 answers

Adding multiple validators to FormGroup in angular2

How can I add multiple validators to a FormGroup. A FormControl can accept an array of validators, however a FormGroup cannot. Is there a workaround aside from creating a single custom validator? I am using rc4.
Maxim
  • 463
  • 1
  • 7
  • 17
8
votes
3 answers

How to add more input fields using a button - Angular 2 dynamic forms

So I used the guide here: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html I need to add more fields to an existing field. I've made something that works, but it's clunky and it resets the form when I hit it. Code below: In…
A. L
  • 9,009
  • 15
  • 53
  • 121
8
votes
3 answers

how to access Native HTML Input element using formControl in Angular 2.0

I'm using Angular 2.0 final release. What i want to do? - i want to show some notifications (warnings, the requirements for the input) only when the input receive focus. Or even better, when his parent (the div) has mouse hover event. Doing this…
AIon
  • 10,703
  • 7
  • 39
  • 66
7
votes
3 answers

How do I clear the FormArray in Angular Reactive Forms

I am doing resetting of form. It resets the whole form but except FormArray. Creating the form and declaring formArray within it createForm(){ this.invoiceForm = this.formBuilder.group({ 'name': ['', Validators.required], 'gst':…
7
votes
3 answers

How to use Angular 2's FormBuilder between multiple components

I am trying to use FormBuilder in a page I have in Ionic 2. First, here is my environment details: Running on Windows 10, and running ionic --version gives me 2.0.0-beta.35 Here is part of my package.json file: ... "@angular/common":…
6
votes
1 answer

How to initialize form group in Angular 4?

I have the following ngOnInit method: ngOnInit() { this.countries = this.sharedService.getCountries(); this.shopService.getCurrentShopFromCache().then(shop => { this.shop = shop; this.myFormGroup = this.fb.group({ …
Burak
  • 5,406
  • 17
  • 64
  • 105
6
votes
8 answers

patch Value in a nested form control using angular2

I need to set a value in a nested control in a FormBuiler and the model is the following: this.addAccForm = this.fb.group({ accid: ['', Validators.required], status: '', cyc: this.fb.array([ this.initCyc(), ]) …
K Oul
  • 225
  • 1
  • 5
  • 11
6
votes
1 answer

angular2 formBuilder group async validation

I'm trying to implement an async validator with no success... My component creates a form with : this.personForm = this._frmBldr.group({ lastname: [ '', Validators.compose([Validators.required, Validators.minLength(2) ]) ], firstname: [ '',…
ylerjen
  • 3,622
  • 1
  • 20
  • 36
6
votes
2 answers

How to check if form control is valid in Angular programatically?

I need to check in the component (not in the template) if a control generated by formBuilder is valid. I tried: if(this.miSpecialForm.controls.miName.dirty){ console.log('Hi mom!'); } but I get the error: Property 'miName' does not exist on type…
user33276346
  • 773
  • 1
  • 7
  • 19
1
2
3
16 17