I am using ng-select and specifically using typeahead to fetch the list from the server as user types. Following example as described in typeahead example : people3$
. My requirement is to add value when user clicks a button (I have id
and label
and corresponding object) but I am failing to understand :
- How can I push Item to
item : Observable<any[]>
I tried doingthis.item = concat(of([{label:this.field.display,id:value}]))
it pushes the value but it does not reflect the value in ng-select until I click somewhere else outside the element. - I tried this solution by
@ViewChild
and onthis.ngSelect.items = [{label:this.field.display,id:value}]
still it does not show value in ng-select.
After adding value in group, I have added the object but still it does not shows, If i click anywhere soon value will be shown.
I want to know
- What possibly can be the reason for this behaviour.
- preferred way to push items in
Observable<any[]>
Here is my ng-select configuration :
<ng-select class="form-control ng-select-padding"
[items]="referenceItems | async"
[hideSelected]="true"
[loading]="searchFailed"
[typeahead]="searchReferenceItems"
bindLabel="label"
bindValue="id"
(change)="setField($event)"
(blur)="onUpdated()"
[formControlName]="field.name" ngDefaultControl>
</ng-select>
//@ TS file
searchReferenceItems = new Subject<object>();
referenceItems: Observable<any[]> ;
Thanks for your kind help