angular-reactive-forms

Forwarding formControlName to inner component in Angular

吃可爱长大的小学妹 提交于 2019-12-07 14:45:42
问题 I have one custom control component <some-input> that i wrapped to <ext-some-input> . SomeInput is encapsulated, has own API and supports reactive forms. ExtSomeInput is created as high-level wrapper over SomeInput . I have following html: <form [formGroup]="form"> <ext-some-input formControlName="name"> </form> and ExtSomeInput 's html: <some-input formControlName="_???_"></some-input> The question is how to forward formControlName to inner SomeInput component? I need to tie the form and

How can I reset Angular Reactive Form

社会主义新天地 提交于 2019-12-07 00:49:57
问题 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(); } } 回答1: Almost ! Use a reactive form for that : <form [formGroup]="myForm"> <mat-form-field class="full-width">

Setting Angular 2 FormArray value in ReactiveForm?

不问归期 提交于 2019-12-07 00:24:42
问题 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

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

↘锁芯ラ 提交于 2019-12-06 20:19:11
问题 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 _fb: FormBuilder ) { } ngOnInit() { this.myForm = this._fb.group({ address: [this.userDetails.address, [<any>Validators.required]], address2: ['', [<any>Validators.required]], city: ['', [<any>Validators.required]], company_address: ['', [<any>Validators.required]]

Angular 5 - Reactive Forms

回眸只為那壹抹淺笑 提交于 2019-12-06 15:49:17
I am working on the reactive forms and I am not able to get the specifically the form control which has changed or updated from UI rather getting the whole form . I tried using valueChanges() but it returns the full form itself rather than giving me the specific changed form control . I tried using the valueChanges() method but no getting what i am expecting You can subscribe to specific form control rather than the entier form lie this way this.form.get('userName').valueChanges(value=> console.log('name change',value)) you can manage subscribe to form controls dynamically like this this.form

Angular PrimeNG dropdown component in reactive forms - initial value

£可爱£侵袭症+ 提交于 2019-12-06 15:44:43
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"> <p-dropdown [options]="results" formControlName="second" (onChange)="onChangeHandler($event)"

Angular reactive form binding not working

假如想象 提交于 2019-12-06 15:41:23
I'm trying to create nested reactive forms here : https://stackblitz.com/edit/angular-mgrfbj This is the project heirarchy: ---create company form (hello.component.ts) --- company details form (company-details.component.ts) --- [ employee details form (employee-details.component.ts) employee details form employee details form ... ] For such nested forms, I have to use ViewProviders and FormGroupDirective as given in this video : The first nested form ( company-details.component.ts ) is working as expected But the second form which is added with *ngFor inside a FormArray is not binding to the

Getting Error: formGroup expects a FormGroup instance. Please pass one in

早过忘川 提交于 2019-12-06 14:37:59
I am new to Angular 2 and unable to resolve this issue even after going through other stack overflow answers. I have just now started learning angular reactive forms and want to try the first example but am stuck. Please help. Here is the HTML form. <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-10 col-md-8 col-sm-offset-1 col-md-offset-2"> <form [formGroup]="signupForm" (ngSubmit)="onSubmit()"> <div id="user-data"> <div class="form-group"> <label for="username">Username</label> <input type="text" id="username" formControlName="username" class="form-control"> </div>

Angular - Form Array push specific index

五迷三道 提交于 2019-12-06 11:18:37
addStop() { const control = <FormArray>this.editForm.controls['stops']; control.push(this.initStop()); } I have this code to add a "stop" at the bottom of the form array. But I want to add the new "stop" not to the last position, but one position before the last stop. This doesn't work for example (not at all, I know that the numbers are wrong. Splice function doesn't exist at ) control.splice(2, 0, this.initStop()); Use FormArray#insert : control.insert(<position>, this.initStop()); 来源: https://stackoverflow.com/questions/44489034/angular-form-array-push-specific-index

Validate if age is over 18 years old with Angular Reactive Forms

独自空忆成欢 提交于 2019-12-06 11:13:51
问题 Is there a way to check if a user is over 18 years of age when they have entered their date of birth using Angular Validators? My form looks like this: <form [formGroup]="authForm" (ngSubmit)="submitForm()"> <label>Date of birth</label> <input formControlName="day" maxlength="2" placeholder="DD" type="text" /> <input formControlName="month" maxlength="2" placeholder="MM" type="text" /> <input formControlName="year" maxlength="4" placeholder="YYYY" type="text" /> <button [disabled]="!authForm