자동 완성을 위해 Angular 4 Typeahead에 ngBootstrap을 사용하고 싶습니다. 원격 데이터 검색에 사용 된 예제는 http가 아닌 Jsonp를 사용하고 있습니다. 그 예제에서 Jsonp를 http로 대체하기위한 정보를 더 찾으려고 노력했습니다. 나는 Observables에 너무 익숙하지 않아서 나는 그것들을 배우고 그들에 대해 더 잘 이해하려고 노력하고있다.ngBootstrap에 http를 사용하여 각도 4에 대해 Typeahead 사용
나는이 example을 보았지만 은 실제로으로 보이며 간단하게 (?) 나뭇잎을 많이 낸다 ... 단순성을 위해?
누군가 올바른 방향을 가리킬 수 있습니까? ngBootstrap Typeahead와 함께 http를 사용하여 좋은 예를 찾고 있습니다.
편집
{
"took": 15,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 9,
"max_score": 4.2456956,
"hits": [
{
"_index": "query-index",
"_type": "autocomplete",
"_id": "AVxqBE-3t2o4jx2g0ntb",
"_score": 4.2456956,
"_source": {
"suggestions": "bruce"
}
},
{
"_index": "query-index",
"_type": "autocomplete",
"_id": "AVxqBE-3t2o4jx2g0ntc",
"_score": 3.064434,
"_source": {
"suggestions": "bruce wayne"
}
},
{
"_index": "query-index",
"_type": "autocomplete",
"_id": "AVxqBE-3t2o4jx2g0ntd",
"_score": 3.064434,
"_source": {
"suggestions": "bruce willis"
}
},
편집 2
export class AutocompleteComponent {
model: any;
searching = false;
searchFailed = false;
constructor(private autocompleteService: Elasticsearch) {}
//formatMatches = (query: any) => query.hits.hits._source.suggestions || '';
//formatMatches = (query: any) => query.hits.hits || '';
formatMatches = (query: any) => <any>response.json().hits.hits || '';
search = (text$: Observable<string>) =>
//search = (text$: Observable<Suggestion[]>) =>
text$
.debounceTime(300)
.distinctUntilChanged()
//.switchMap(term =>
//Observable.fromPromise(this.autocompleteService.search(term)
.switchMap(term =>
this.autocompleteService.search(term)
.do(() => this.searchFailed = false)
.catch(() => {
this.searchFailed = true;
return Observable.of([]);
}))
.do(() => this.searching = false);
}
나는 내가 나의 일을 찾은 것 같아,하지만 난 그것을 한 방법을 정확하게 확실하지 ma에. 여기에 게시 한 예를 사용했습니다. –