oferh / ng2-completer

Angular 2 autocomplete component
http://oferh.github.io/ng2-completer/
MIT License
348 stars 172 forks source link

[dataSource] doesn't detect changes automatically #354

Open poolpo opened 6 years ago

poolpo commented 6 years ago

When I change the data sources array, the dropdown doen't change its old values.

Here's an example:

let dS = ["a", "b"];
setTimeout(()=>{
       dS = ["c"];
}, 5000);

<ng2-completer [disableInput]="isDisabled" [ngModel]="value" [datasource]="dS" [minSearchLength]="0" [openOnClick]="true" (selected)="onSe    lectedItem($event)" (opened)="onBlur($event)"></ng2-completer>

After 5 secons, the dropdown options still being ["a", "b"].

Is there another way of achieving this?

oferh commented 6 years ago

Hi,

can you provide a plunker that reproduces it?

daanstolp commented 6 years ago

I'm not sure if the topic starter still has this issue, but I am able to reproduce this issue. Updating the source data when using LocalData doesn't update the dropdown. See this plunk and the comments on lines 40 and 43.

So the question remains: how to update local data such that the dropdown reflects this?

(My particular scenario is a pair of dropdowns, where the selection of the first dropdown determines the data set of the second dropdown).

Bloodcast69 commented 6 years ago

Having the same problem, I've got a dropdown with some items. If I click on item 1, I'm passing values to searchData array. When I click on item 2, I'm also passing values to searchData.

Problem is here, that if I pass first set of data, click on input and then pass the second set of data, my input doesn't detect changes in ng2-completer dropdown. I have to push a keyboard key and then my ng2-completer dropdown shows new values.

@daanstolp , @oferh any solutions for this?

shaic commented 6 years ago

Also having the same problem like @Bloodcast69 - no identification of changes to auto refresh & display the relevant data.

@oferh - any solution or plan to address this?

Bloodcast69 commented 6 years ago

@oferh We're waiting to hear something from you.

Zakaria59 commented 6 years ago

same problem here

jjdii commented 5 years ago

Same issue here @daanstolp @Bloodcast69 @poolpo @Zakaria59

I'm using a local dataService. Depending on what type of profile the user has selected on my app, my completer loads different sets of data. But it won't actually update the dropdown items until the dropdown is focused and I start typing.

Any solutions? Or are there any other recommended plugins that have this functionality?

odesenvolvedor commented 1 year ago

You can use Subject items Example:

`protected cities: Subject<City[]> = new Subject();

constructor( private completerService: CompleterService ) { this.dataService = this.completerService.local(this.cities, 'name', 'name'); } `

bhuvancom commented 1 year ago

glad i searched just after wasting 20 minutes