kadoshms / ionic2-autocomplete

Ionic 2 autocomplete component
MIT License
149 stars 108 forks source link

After selection, searchbar.getSelection() gives always the previous selected object #150

Open GCoe opened 6 years ago

GCoe commented 6 years ago

Hi, I'm trying get the currently select object with this.searchbar.getSelection() .

The HTML :

<ion-col col-3> <ion-auto-complete #searchbar (autoBlur)="ProcessBlur()" (itemSelected)="ProcessItemSelected()" [dataProvider]="completeTestService" [(ngModel)]="myModelObject.name" [options]="{ placeholder : 'Select country' ,type : 'text'}"></ion-auto-complete> </ion-col> The TS code :

` ProcessItemSelected(){ console.log("Selected country -> ", this.searchbar.getSelection()) } ProcessBlur(){ console.log("Selected country on blur -> ", this.searchbar.getSelection()) }

When a new selection is done, the property myModelObject.numericCode is updated but the result from ProcessItemSelected() and ProcessBlur is always the object select before the click, not the current select object`

ghost commented 6 years ago

I had the same issue and here's what I did. I used the inbuilt itemSelected event

<ion-auto-complete [dataProvider]="completeTestService" [template]="withFlags" #searchbar (itemSelected)="selectedItem($event)"></ion-auto-complete>

Then in my controller. I have the function selectedItem(value) { console.log(value) } It gets the selected item object

GCoe commented 6 years ago

Thank you @yusufabayomio .

I'll try it. Ar'you using ionic2-autocomplete on a production environment ?

ghost commented 6 years ago

No. Its still on dev