Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

autocomplete-service.ts

20 lines491 Bytes

1import { HttpClient } from '@angular/common/http'
2import { Injectable, inject } from '@angular/core'
3import { of } from 'rxjs'
4​
5interface Response {
6 suggestions: Array<string>
7}
8​
9@Injectable({
10 providedIn: 'root',
11})
12export class AutocompleteService {
13 #http = inject(HttpClient)
14 getSuggestions = (term: string = '') =>
15 term.trim() === ''
16 ? of({ suggestions: [] })
17 : this.#http.get<Response>(
18 `/api/autocomplete?term=${encodeURIComponent(term)}`,
19 )