angular-reactive-forms

Iterating through a FormArray containing FormGroups with *ngFor

喜欢而已 提交于 2020-08-22 05:42:59
问题 In Ionic 2 I am trying to create a dynamic form which shall display a list of toggle buttons. To do so I am trying to use a FormArray and relied on the Angular doc and mainly on this post Based on this, I implemented the following <form *ngIf="accountForm" [formGroup]="accountForm"> <ion-list> <!-- Personal info --> <ion-list-header padding-top> Informations personnelles </ion-list-header> <ion-item> <ion-label stacked>Prénom</ion-label> <ion-input formControlName="firstname" [value]="(user |

Iterating through a FormArray containing FormGroups with *ngFor

耗尽温柔 提交于 2020-08-22 05:42:19
问题 In Ionic 2 I am trying to create a dynamic form which shall display a list of toggle buttons. To do so I am trying to use a FormArray and relied on the Angular doc and mainly on this post Based on this, I implemented the following <form *ngIf="accountForm" [formGroup]="accountForm"> <ion-list> <!-- Personal info --> <ion-list-header padding-top> Informations personnelles </ion-list-header> <ion-item> <ion-label stacked>Prénom</ion-label> <ion-input formControlName="firstname" [value]="(user |

ionChange works just once on the page and reactive form validators don't take effect every time a select it's changed

眉间皱痕 提交于 2020-08-10 19:35:10
问题 What I wanted to achieve is to make different formControls mandatory or to clear them depending on a select option and it works, but the validators work just once on the page and not every time I change the select option. If I select "cm" and clear the input and go and select "ft" it works, but if I clear the "ft" input and go and select "cm" it doesn't work and the "ft" is now mandatory even though I wrote to clear the validator on "ft" if "cm" is selected. If you guys have any idea why I

How to unit test a reactive component where ngControl is decorated with @Self

有些话、适合烂在心里 提交于 2020-08-08 06:13:17
问题 I've written a reactive component by injecting the NgControl and which is decorated using the @Self decorator. My problem is related to unit testing of such component. Please look at the code below: Disclaimer: I've quickly copied the code and made some inline changes. So, this might not be a compiler happy code. My Reactive Component: @Component({ selector: 'text-input', templateUrl: '<input type="text" class="native_input" />' }) class TextInput implements ControlValueAccessor { protected

ERROR Error: Cannot find control with path

匆匆过客 提交于 2020-08-07 08:18:26
问题 I'm new to Angular and tried to extend the example code from: Angular 4 Form FormArray Add a Button to add or delete a form input row If a certain option was picked in a dropdown, new options for that option should be expressable. I got to this point without problems, but implementing the formControlName Tags for those 'lower-tier-options' are throwing me an error: ContentComponent.html:56 ERROR Error: Cannot find control with path: 'inhalt -> 0 -> optionsKey'(…) the exact line in the .html

ERROR Error: Cannot find control with path

半城伤御伤魂 提交于 2020-08-07 08:17:45
问题 I'm new to Angular and tried to extend the example code from: Angular 4 Form FormArray Add a Button to add or delete a form input row If a certain option was picked in a dropdown, new options for that option should be expressable. I got to this point without problems, but implementing the formControlName Tags for those 'lower-tier-options' are throwing me an error: ContentComponent.html:56 ERROR Error: Cannot find control with path: 'inhalt -> 0 -> optionsKey'(…) the exact line in the .html

angular 5 conditionally validate field based on another field's value

巧了我就是萌 提交于 2020-07-09 13:27:45
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

angular 5 conditionally validate field based on another field's value

谁说我不能喝 提交于 2020-07-09 13:24:49
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

angular 5 conditionally validate field based on another field's value

核能气质少年 提交于 2020-07-09 13:24:03
问题 How to conditionally validate a field based on another field's value? Here's what i've tried but it seems not to work this.PDform = _formbuilder.group({ [...] 'intlNumber': ['',this.nationality == 'Abroad' ? Validators.compose([Validators.pattern(this.phoneNumberExp), Validators.maxLength(14), Validators.minLength(11), Validators.required]) : Validators ] [...] }) 回答1: You can change the validators for a form control when the value of another form control changes by subscribing to the

Why am I getting error in *ngIf of angular reactive form

时间秒杀一切 提交于 2020-07-08 20:46:06
问题 I understand this is a very stupid question and for someone with my SOF reputation should not be asking.Howvever I am pulling my hair and can't seem to understand what I am doing wrong. I am referring to an example on Stackblitz to create reactive form. In Stackblitz everything seems fine and my code works fine too.But in vs code I see error Identifier 'nameType' is not defined. '__type' does not contain such a memberAngular Code : <div> <label>Name Type</label> <mat-select formControlName=