optimistex / ngx-select-ex

Angular based replacement for select boxes
https://optimistex.github.io/ngx-select-ex/
MIT License
111 stars 42 forks source link

ngx-select-ex default value is not working. #141

Closed rskthiyagu closed 5 years ago

rskthiyagu commented 5 years ago

I have to populate the select box in some scenario. In that scenario, i have update the default value variable value, It doesn't work. I have also tried to update the form control value. It is reflected in form control, but not in ngx-select-ex component. Please suggest me any solutions.

optimistex commented 5 years ago

@rskthiyagu Could you make an example there https://stackblitz.com/

dalibor-sanzeru commented 5 years ago

I had similar problem, but then I realized that i was using STRING combined with NUMBERS !!! That was reason why in reactive forms selected value on ngx-select was not prefilled.

MY scenario was: 1) take values from URL and pull it to FormGroup (user sent link to some friend). 2) I was filling up string for value e.g.: -> this.formGroup.controls['sort'].setValue("2"); 3)I filled items this way e.g.: this.items = [{id: 1, text: "Sort by name"}, {id: 2, text: "Sort by date"}];

You need to have same data types! this wasnt my case becasue from REST I get typed number, but from URL i get only number as string.

Please check if your datatypes match.

AlexWalkerson commented 5 years ago

I ran into a similar issue when I change the list of options dynamically and want to set default value. Here is a simple example: https://stackblitz.com/edit/angular-g8p2mh

optimistex commented 5 years ago

@AlexWalkerson The fast solution: https://stackblitz.com/edit/angular-issues141?file=src/app/app.component.ts

I've used the timer 0 because the items sets to the component by Angular's event, so we want update it's data after setting up the item list. Timer 0 let us skip one processors tick and do our thing in the next available moment.

abdelbaki commented 4 years ago

Hello, https://stackblitz.com/edit/angular-issues141?file=src/app/app.component.ts work fine for array of string. But when i use a array of object, it don't work.

this is my example : https://stackblitz.com/edit/angular-issues141-md6trm?file=src/app/app.component.ts