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