我创建了一个搜索栏,并从mongodb返回结果。我想显示搜索数据的下拉列表,并单击每个下拉列表。
我尝试在结果部分中创建,但没有成功。我还尝试创建一个,并将结果放在该部分中,但它仅显示单词link。
\\ I tried this but it just returned the word r.link:
<ng-template #rt let-r="result" let-t="term">
<a href='r.link'><ngb-highlight [result]="r.title" [term]="t"></ngb-highlight></a>
</ng-template>
\\ I also tried this but it broke it
<ng-template #rt let-r="result" let-t="term">
<ngb-highlight [result]="<a href='r.link'>r.title</a>" [term]="t"></ngb-highlight>
</ng-template>
\\ I would like to add a link to this dropdown for each title.
\\ This is my html file
<ng-template #rt let-r="result" let-t="term">
<ngb-highlight [result]="r.title" [term]="t"></ngb-highlight>
</ng-template>
<div class="row">
<div class="col-xl-12">
<div class="row">
<div class="form-group col-md-12">
<input id="search" name="search" [ngbTypeahead]="search" type="text" placeholder="Search for solutions..." class="form-control-search-bar form-control-underlined amcs-search" [resultTemplate]="rt" [inputFormatter]="title">
</div>
</div>
</div>
</div>
\\ This is my search.component.ts
search = (text$: Observable<string>) =>
text$.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term =>
this._service.search(term).pipe(
tap((searchResults) => { this.searchFailed = false; }),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
)
title = (x: {tag: string}) => x.tag;
Any help would be appreciated. Thank you