angular-reactive-forms

Error during dynamic form creation from json Cannot find control with name: 'data'

筅森魡賤 提交于 2019-12-03 16:19:12
I am using angular 7 appplication and i am writing a generic dynamic form creator. I am using reactive forms and ng-template and <ng-container *ngTemplateOutlet> for recursively displaying the form element.The code of the project could be seen Here . But i am facing the following error ERROR Error: Cannot find control with name: 'data' at _throwError (forms.js:1775) at setUpControl (forms.js:1683) at FormGroupDirective.push../node_modules/@angular/forms/fesm5/forms.js.FormGroupDirective.addControl (forms.js:4532) at FormControlName.push../node_modules/@angular/forms/fesm5/forms.js

Show Validation Message on submit in Angular 4 Reactive Forms

℡╲_俬逩灬. 提交于 2019-12-03 16:15:47
I am using Angular 4, Reactive forms.I want to show validation error message when the user clicks on Submit/Create Account button. Here is the HTML and typescript code that I am using. <form [formGroup]="signupForm" (ngSubmit)="onSubmit()"> <div class="form-group"> <input type="text" id="firstname" name="firstname" formControlName="firstname" placeholder="First Name"> <span *ngIf="!signupForm.get('firstname').valid && signupForm.get('firstname').touched" class="help-block"> Please Enter First Name (Minimum 2 Characters)</span> </div> <div class="form-group"> <input type="text" id="lastname"

Angular 4 patchValue based on index in FormArray

社会主义新天地 提交于 2019-12-03 15:01:41
问题 I am looking to update a formArray after the user adds a value in an empty created control. Currently when the user selects to add a new item i build onto the formArray with empty values. buildItem(item?: any, key?: any): FormGroup { // Item will pass undefined for initial buildItem in onLoad and new items let itemName: string; let keyValue: string; if (item === undefined) { itemName = ''; key = '' } else { itemName = item.name; keyValue = key }; /** * Builds a single item for form group

Angular 4 patchValue based on index in FormArray

[亡魂溺海] 提交于 2019-12-03 09:50:16
I am looking to update a formArray after the user adds a value in an empty created control. Currently when the user selects to add a new item i build onto the formArray with empty values. buildItem(item?: any, key?: any): FormGroup { // Item will pass undefined for initial buildItem in onLoad and new items let itemName: string; let keyValue: string; if (item === undefined) { itemName = ''; key = '' } else { itemName = item.name; keyValue = key }; /** * Builds a single item for form group array in the collectionForm. */ return this.formBuilder.group({ item: [itemName || '', Validators.required]

How to use pipes in Angular 5 reactive form input

∥☆過路亽.° 提交于 2019-12-03 06:34:25
问题 I am trying to figure out how to use a pipe within a reactive form so that the input is forced into a currency format. I have already created my own pipe for this which I have tested in other areas of the code so I know it works as a simple pipe. My pipe name is 'udpCurrency' The closest answer I could find on stack overflow was this one: Using Pipes within ngModel on INPUT Elements in Angular2-View However this is not working in my case and I suspect it has something to do with the fact that

Angular 4 array validation

耗尽温柔 提交于 2019-12-03 03:10:00
I need help with formArray validation in reactive form . I want validate each item in array, but i have no idea how can i do that. Thanks. html code: <label for="name">name:</label> <input formControlName="name" id="name" type="text"> <div *ngIf="name.invalid && (name.dirty || name.touched)"> <div *ngIf="name.errors.required"> required </div> </div> TypeScript code: createForm() { this.form = this.fb.group({ person: this.fb.array([this.initItemRows()]) }); } initItemRows() { return this.fb.group({ name: [''], info: [''] }); } addNewRow() { const control = <FormArray>this.form.controls['person'

How to get index of changed item in angular form array

﹥>﹥吖頭↗ 提交于 2019-12-02 23:01:20
I'm using Angular 4 with reactive forms. I have a form array that I am trying to tie to an array I keep track of in my component. I'm using reactive forms so I can have the validation, so I don't want to use the template forms approach. I add items to the form array like so: createFormWithModel() { this.orderForm = this.fb.group({ orderNumber: [this.order.ProductBookingOrder], orderDate: [this.order.PurchaseOrderIssuedDate], lineDetailsArray: this.fb.array([]) }) const arrayControl = <FormArray>this.orderForm.controls['lineDetailsArray']; this.order.ProductBookingDetails.forEach(item => { let

How to use pipes in Angular 5 reactive form input

那年仲夏 提交于 2019-12-02 21:55:14
I am trying to figure out how to use a pipe within a reactive form so that the input is forced into a currency format. I have already created my own pipe for this which I have tested in other areas of the code so I know it works as a simple pipe. My pipe name is 'udpCurrency' The closest answer I could find on stack overflow was this one: Using Pipes within ngModel on INPUT Elements in Angular2-View However this is not working in my case and I suspect it has something to do with the fact that my form is reactive Here is all the relevant code: The Template <form [formGroup]="myForm" #f="ngForm"

Angular dynamic form nested fields

房东的猫 提交于 2019-12-02 20:00:41
问题 With the help of https://angular.io/guide/dynamic-form, i am making a dynamic form where i am in the need to display two fields at first. new TextboxQuestion({ key: 'firstName', label: 'First name', value: '', required: true, order: 1 }), new TextboxQuestion({ key: 'lastName', label: 'Last name', value: '', required: true, order: 2 }), These two fields needs to be at first on loading. After this i will have two buttons as add and remove . <button (click)="addNew()"> Add </button>     <button

Angular table row contains sum of columns dynamically using Reactive Forms

二次信任 提交于 2019-12-02 18:31:42
问题 i'm working in angular project where i want to show a table with two columns and dynamic row and last row conatins sum of each column when user type any number , this is what i want to achieve : element | FR | EN | ------------------- elem A | | | ------------------- elem B | | | ------------------- elem C | | | ------------------- Total | | | and this is my angular code : componenet.ts : listDecompositionLibelle: string[] = ['elem A', 'elem B','elem C']; ngOnInit() { this.valuesForm = this