Skip to content
Snippets Groups Projects
Commit eaaa17e8 authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

fix(searchAddress) : waiting the result of api before calling an other one

parent 26a4aee5
No related branches found
No related tags found
3 merge requests!68Recette,!67Dev,!66Fix/form design create structure
......@@ -6,10 +6,11 @@
placeholder="ex: 20 rue du lac, Lyon"
(input)="onSearchChange($event.target.value)"
class="form-input"
autocomplete="off"
#searchAddress
/>
</div>
<div class="autocomplete-items">
<div class="autocomplete-items" *ngIf="!isAlreadySearch">
<p *ngFor="let hit of data" (click)="selectedResult(hit)" class="autocomplete-item">
{{ parseHitToAddress(hit) }}
</p>
......
......@@ -10,6 +10,7 @@ import { AddressService } from '../../service/address.service';
export class AddressAutocompleteComponent implements OnInit {
public readonly AUTOCOMPLETE_NBR = 5;
public data = [];
public isAlreadySearch = false;
@ViewChild('searchAddress', { static: true }) searchAddress: ElementRef;
@Output() selectedAddress: EventEmitter<Address> = new EventEmitter<Address>();
@Output() inputAddress: EventEmitter<any> = new EventEmitter<any>();
......@@ -24,11 +25,14 @@ export class AddressAutocompleteComponent implements OnInit {
}
}
public onSearchChange(searchString: string) {
if (!this.isAlreadySearch) {
this.isAlreadySearch = true;
this.addressService.searchAddress(searchString).subscribe((data) => {
this.data = data.hits.hits.slice(0, this.AUTOCOMPLETE_NBR);
this.isAlreadySearch = false;
});
}
this.inputAddress.emit();
this.addressService.searchAddress(searchString).subscribe((data) => {
this.data = data.hits.hits.slice(0, this.AUTOCOMPLETE_NBR);
});
}
public selectedResult(hit: any): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment