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