ng2-select icon indicating copy to clipboard operation
ng2-select copied to clipboard

Dynamic list values

Open yusijs opened this issue 8 years ago • 17 comments

I'm trying to create a select drop down that populates based off of an http request.

Relevant code is public clients: any[] = [];

ngOnInit() {
    this._clientListService.getClients()
      .subscribe(res => {
        this.clients = res;
        console.log(this.clients)
      })
  }
<ng-select [allowClear]="true"
              [items]="clients"
              (data)="refreshValue($event)"
              placeholder="Please select a client">
</ng-select>

However, the dropdown options are blank. Populating this on a

    <select class="form-control">
      <option *ngFor="let client of clients" value="client.client_id">{{client.client_id}} - {{client.client_id_name}}</option>
    </select>

Any clues? I'm guessing it's change detection not kicking in.

Ftr, I'm seeing you refer to a "query" option, but I can't find it anywhere. I find a couple mentions in your source, but not as input/output shrug

yusijs avatar May 20 '16 18:05 yusijs

This functionality is pretty important at this point, I've looked through the proposed async solutions posted elsewhere and most of them seem 'hacky' or just plain don't work. Is there any ETA on when this library will support change detection and allow us to add items asynchronously?

Daeluse avatar Jun 30 '16 15:06 Daeluse

I think this is the same problem I was having on RC.4 and 1.0.3.

I fixed it by putting the ng-select inside an ngIf.

<div *ngIf="clients.length > 0"> ... </div>

jkwiz avatar Jul 12 '16 20:07 jkwiz

+1

curlyfro avatar Jul 19 '16 15:07 curlyfro

+1 @jkwiz Thanks! That worked like a charm!!

Kasper86 avatar Jul 22 '16 07:07 Kasper86

+1

GreenRover avatar Oct 31 '16 15:10 GreenRover

@jkwiz if it used to work, this doesn't now. Not your fault, but this is a terrible miss by Valor and it seems like they have abandoned it.

twaldron avatar Nov 04 '16 19:11 twaldron

+1

slimshady5 avatar Jan 07 '17 23:01 slimshady5

Fixed this in https://github.com/valor-software/ng2-select/pull/610

toke182 avatar Jan 24 '17 13:01 toke182

This might help: https://github.com/valor-software/ng2-select/issues/635#issuecomment-281094377

JimJafar avatar Feb 20 '17 17:02 JimJafar

@jkwiz Thanks! That worked like a breeze

sujitnale123 avatar Jul 24 '17 13:07 sujitnale123

I also faced the same issue. I used *ngIf="data.length!=0" to resolved it( this solution hide select for first time). but i found new way to resolve it, assign a empty value to it like public data:any = [ {id: '', text:' '} ]; hope it will help you.

farhaan008 avatar Nov 11 '17 17:11 farhaan008

not working yet..

PuneetChauhan1 avatar Apr 11 '18 10:04 PuneetChauhan1

I am still having issue binding data to ng2-select, can anybody help please? <ng-select [multiple]="true" [items]="items" > items: Array = [ { "id": 1, "text": "Table" }, { "id": 2, "text": "Chair" }, { "id": 3, "text": "Light" }

];

ChandraTerli avatar May 16 '18 15:05 ChandraTerli

Component will not detect a change. Instead you need to do:

this.items = [...this.items, {id: 1, name: 'New item'}];

leandromatilla avatar Oct 26 '18 14:10 leandromatilla

I fixed it by putting the ng-select [items] value with "async".

<ng-select [items]="dropdownList | async">

leandromatilla avatar Oct 26 '18 14:10 leandromatilla

Component will not detect a change. Instead you need to do:

this.items = [...this.items, {id: 1, name: 'New item'}];

Good:)

lygstate avatar Mar 09 '19 16:03 lygstate

this.items = [...this.items, {id: 1, name: 'New item'}];

Solved my Problem Thanks

nikhilkhot46 avatar Apr 29 '19 05:04 nikhilkhot46