angular2-formbuilder

angular2 cannot read property 'validator' of undefined when use ngFormModel (ES6)

你离开我真会死。 提交于 2019-12-12 04:06:07
问题 I got some problem when use ngFormModel directive with form it said "TypeError: Cannot read property 'validator' of undefined in form_one (I write this code from NG-BOOK 2 Tutorial but it's not work!) import {Component} from 'angular2/core' import { FORM_DIRECTIVES, FormBuilder, ControlGroup, Validators } from 'angular2/common' @Component({ selector: 'demo-form-sku-builder', directives: [FORM_DIRECTIVES], template: ` <div class="ui raised segment"> <h2 class="ui header">Demo Form: Sku with

Using setControl in nested reactive form

陌路散爱 提交于 2019-12-11 19:56:38
问题 I would like to know what I have to do to use the "setControl" and "get" in a reactive form when I have an array inside of another formBuilder group. For instance: this.formulario = this.formBuilder.group({ title: [this.racPessoa.title, [Validators.required]], description: [this.racPessoa.description, [Validators.required]], person: this.formBuilder.group({ idPerson:[this.racPessoa.person.idPerson], name:[this.racPessoa.person.nome], personDocument: this.formBuilder.array([]) }), }); In the

Angular 2 - Creating form in a subscription causes crash saying the formGroup is undefined

心已入冬 提交于 2019-12-11 09:23:29
问题 I've got some data in my Firebase database, this data I want to apply to a form via FormBuilder . It works somewhat good but I get errors more often than not saying formGroup expects a FormGroup instance. Please pass one in. . What doesn't make sense is that when I apply new changes to the database which cause the subscription to fire, I get the error. Despite this.settingsForm being set before and after the subscription runs after updating. Here's the subscription: this.eventSubscription =

How to write custom form validator (model-driven) that depends on current component's property value in Angular2

十年热恋 提交于 2019-12-11 05:16:23
问题 I am working with the latest angular2 forms and struggling with this seems-to-be-simple task. I want to have a custom validation function that is able to read the current component's property and validate the input based on that. Here is the example plnkr: http://plnkr.co/edit/bNFjNsCfhYjoqKaRZgQU?p=preview In this example, I have a username field which is always required, and a password field that will only be needed if the customer is an existing one. My form declaration is: this.loginForm

Setting initial value Angular 2 reactive formarray

ⅰ亾dé卋堺 提交于 2019-12-10 18:17:31
问题 I am trying to set the initial value for an angular 2 reactive form formArray object. Even though the json object used to set the form value contains an array value with multiple entries, only the first entry is shown and the "form.value" also only shows the first entry. I am using the syntax (<FormGroup>this.myForm).patchValue(value, { onlySelf: true }); to set the initial value on the form. Here is a plunker demonstrating the issue: https://plnkr.co/edit/j1S80CmPBF1iHI5ViEia?p=preview I

AngularDart: Creating a Form with Reactive Form Builder

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:25:34
问题 I'm trying to create from using AngularDart 5 , angular_forms 2 . The API seems to be very different from angular_forms 1 and I cannot figure out how to create a FormGroup using FormBuilder and ControlGroup . Below is my code. LoginComponent.dart import 'dart:convert'; import 'package:angular/angular.dart'; import 'package:angular_forms/angular_forms.dart'; @Component( selector: 'login-comp', templateUrl: 'login_component.html', styleUrls: ['login_component.css'], directives: [formDirectives,

Angular Form Control valueChanges not working

别说谁变了你拦得住时间么 提交于 2019-12-10 02:46:55
问题 I want to get one of my forms ("family") value if changed by subscribe but it seems something wrong, because I got nothing on my console's log. import { Component , AfterViewInit } from '@angular/core'; import {FormGroup,FormBuilder} from '@angular/forms'; import {Observable} from 'rxjs/Rx'; @Component({ selector: 'app-root', template: `<h1>Hello World!</h1> <form [formGroup]="frm1"> <input type="text" formControlName="name" > <input type="text" formControlName="family"> </form> `, }) export

Nested groups in Angular2 forms?

我怕爱的太早我们不能终老 提交于 2019-12-08 13:29:16
问题 I'm using the reactive forms module in Angular 2 to create a form with several nested groups. My 'trust' form has an array of contacts at <FormArray>this.newTrustForm.controls['contact'] One of the fields in the 'contact' group is an array of 'email' groups and I tried finding it here, but alas, no. Where would I then find it? <FormArray>this.newTrustForm.controls['contact'].controls['email'] I setup my form with the following. constructor(private _fb: FormBuilder) { } ngOnInit() { this

Validators same as other value in form

时间秒杀一切 提交于 2019-12-08 06:45:48
问题 I am wondering if there is a Validator that compares two different values from the same form - lets say I have the following: this.loginForm = fb.group({ email: ["", Validators.required], password: ["", Validators.required], repeatPassword: ["", Validators.required] }); I found this in documentation, however it wasn't very helpful. Any ideas? 回答1: You need to assign a validator to a complete form group to implement this. Something like that: this.form = fb.group({ name: ['', Validators

Validation on a list of checkboxes Angular 2

巧了我就是萌 提交于 2019-12-07 05:49:40
问题 I have a list of business units that are rendered as checkboxes on a registration form along with a textbox field and am doing validation. <label for="inputFirstName" class="sr-only">First name</label> <input type="text" formControlName="firstName" class="form-control" placeholder="First name"> <div class="checkbox" *ngFor="let bu of businessUnits"> <label><input type="checkbox" #instance value="{{bu.BuName}}" (click)="getCheckBoxValue(instance.checked, bu.BuName)">{{bu.BuName}}</label> </div