angular2-formbuilder

FormBuilder group is deprecated

删除回忆录丶 提交于 2021-01-18 13:58:09
问题 I migrated my project to angular 11 and I noticed that the global validations that I added make FormBuilder.group deprecated with the message: group is deprecated: This api is not typesafe and can result in issues with Closure Compiler renaming. Use the `FormBuilder#group` overload with `AbstractControlOptions` instead. so this is deprecated: ingredientForm = this.fb.group({ ingredientType: ['', Validators.required], ingredientFlavor: [''], isMultiFlavor: [''], ingredientBrand: [''],

How to initialize form group in Angular 4?

拜拜、爱过 提交于 2020-06-11 05:10:31
问题 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({ name: [this.shop.name[this.shop.defaultLanguage.code], [Validators.required]], address: [this.shop.address.address], city: [this.shop.address.city], state: [this.shop.address.state], country: [this.shop.address.country, [Validators.required]], phone: [this.shop.phone], email: [this

Disable the entire form at once (Angular reactive form)

半腔热情 提交于 2020-05-28 12:00:38
问题 Is there any way to disable the entire form in angular when using Reactive forms. I know it is possible to make them disable one by one. this.tempForm = this.fb.group({ m26_type: '', m26_name: '' }) this.tempForm.get('m26_type').disable(); Is it possible to disable the whole form rather than make every controller disable separately? 回答1: this.tempForm.disable(); Disables the control. This means the control will be exempt from validation checks and excluded from the aggregate value of any

Angular Validators: Can I add styling to form elements based on their validators?

青春壹個敷衍的年華 提交于 2020-01-06 05:43:07
问题 I'm using Angular with Forms version 4.1.0 and Material version 2.0.0-beta.8. I have fields that need to be marked as required based on a configuration stored in a database table, so the specific fields that are required can change depending on that configuration and are not known at development time. I am dynamically setting Validators.required on my form controls based on that configuration, and that is all working fine (i.e. the appropriate fields are turning red if you leave them blank

Angular 2/4 Edit Form Populate FormArray Controls

元气小坏坏 提交于 2020-01-01 04:42:04
问题 I'm trying to implement an edit form for a model with nested attributes (FormArray). I'm having trouble with the syntax and I'm uncertain whether I'm on the right track. The attributes for the main form work, it's the nested form I'm having problems with. Here's what I have so far. Here I initiate the form group: private initForm() { this.subscription = this.expenseService.getExpense(this.id) .subscribe( expense => { this.expense = expense; this.patchForm(); } ); this.expenseEditForm = this

How to assign and validate arrays to forms in Angular2

荒凉一梦 提交于 2020-01-01 03:18:05
问题 My model ( this.profile ) in javascript has a property called emails , which is an array of {email, isDefault, status} Then I defined it as below this.profileForm = this.formBuilder.group({ .... other properties here emails: [this.profile.emails] }); console.log(this.profile.emails); //is an array console.log(this.profileForm.emails); // undefined in html file I used it as <div *ngFor="let emailInfo of profileForm.emails"> {{emailInfo.email}} <button (click)="removeEmail(emailInfo)"> Remove <

Angular2 ReactiveFormsControl: how to bind radio buttons?

牧云@^-^@ 提交于 2019-12-22 11:27:33
问题 I'm using ReactiveFormsModule of Angular2 to create a component that contains a form. Here is my code: foo.component.ts constructor(fb: FormBuilder) { this.myForm = fb.group({ 'name': ['', Validators.required], 'surname': ['', Validators.required], 'gender': [] }); } foo.component.html <div class="two fields"> <div class="four wide field"> <label>Name*</label> <input type="text" [formControl]="myForm.controls.name"/> </div> <div class="four wide field"> <label>Surname*</label> <input type=

patch Value in a nested form control using angular2

匆匆过客 提交于 2019-12-22 09:03:25
问题 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(), ]) }) initCyc() { return this.fb.group({ cycid: ['', Validators.required], name: ['', Validators.required], description: ['', Validators.required], status: ['', Validators.required], det: this.fb.group({ dcycid: ['', Validators.required], status: ['', Validators.required] }) }) I need to