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

api.ts

18 lines505 Bytes

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