question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting `ERROR TypeError: Value must be a string or an array` when binding to [formControlName]

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
danilocgracianocommented, May 9, 2018

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.

0reactions
luis-guzman-datumcommented, Feb 22, 2022

Lo solucione de la siguiente manera

this.myOptions.push({ label: label, value: value+‘’ });

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found