在将其重定向到链接之前,我仍然必须双击建议的搜索。最近我为tabindex
和hide()
方法添加了show()
以下是我的代码:
getSuggestion(name) {
$('.suggestion').show();
this.search
.getSuggestion(name)
.subscribe(
name => this.results = name,
error => alert(error),
);
}
hide($event) {
this.suggest = false;
}
show($event) {
this.suggest = true;
}
showEmployee(id: string) {
this.route.navigate(['/information/employees', id]);
this.results = [];
}
<section class="search-bar-wrapper" tabindex="-1" (focusin)="show($event)" (focusout)="hide($event)">
<div class="ui right action left icon input fullwidth" >
<input type="text" placeholder="Search" (keyup)="getSuggestion($event.target.value)">
<div class="suggestion" *ngIf="results.length > 0 && suggest === true">
<div *ngFor="let result of results">
<div class="search-res" (click)="showEmployee(result._id)"> {{ result.name }} </div>
</div>
</div>
</div>
</section>