Getting `ERROR TypeError: Value must be a string or an array` when binding to [formControlName]
See original GitHub issueI need to generate the dropdown component dynamically. When trying to bind the formControlName
, it throws ERROR TypeError: Value must be a string or an array.
See the console of https://stackblitz.com/edit/angular-6z4n2b?file=app%2Fdrop-down%2Fdrop-down.component.html
Removing the line [formControlName]="config.name"
fixes the error, but I need to bind it to the control to get the values.
Any idea whats wrong?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
I want to bind a string value in angular to a form control but it ...
the value of details.empRecruitmentType is 'E' so the selected value of form control (item.typeDesc) must be "full time" but it keeps "contract" ...
Read more >How to Use Angular FormArray(s) within FormGroup(s) In ...
Are you trying to use a FormArray on a dynamic/reactive Angular Form, but it is not working? This should help you solve your...
Read more >Building dynamic forms - Angular
Dynamic forms are based on reactive forms. To give the application access reactive forms directives, the root module imports ReactiveFormsModule from the @ ......
Read more >A thorough exploration of Angular Forms - InDepth.Dev
In order to get the most out of the Forms API, we must ensure that we look over ... <form> <input ngModel name="option"...
Read more >kendo-dropdown formgroup - Expected initial value of type ...
Hi Bryian, As the error message suggests, the component needs to be bound to a complex object value, but is the formControl likely...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi,
I’m have been the same problem related by art-mickiewicz, in my case the problem happens when the model.id is integer, but the options generated by my option list have to be string, using the ngModel directive.
So, using the solution proposed here the values are converted automatically from int to string, and works fine.
'<div class="form-group required" formGroupName="pais"> <label class="control-label" for="pais">País</label> <ng-select formControlName=“id” [options]=“paisList | options : ‘id’ : ‘descricao’”[(ngModel)]=“municipio.pais.id” [allowClear]=“true”> </ng-select>
</div>'It would be a greate help if the author implements this new feature for us.
Lo solucione de la siguiente manera
this.myOptions.push({ label: label, value: value+‘’ });