common-cents-web/src/app/services/category.service.ts
2026-02-19 20:54:00 -06:00

24 lines
675 B
TypeScript

import { Injectable, signal } from '@angular/core';
import { HttpService } from './http.service';
@Injectable({
providedIn: 'root',
})
export class CategoryService {
private internalCategories = signal<Category[]>([]);
public readonly categories = this.internalCategories.asReadonly();
public readonly categoryPath = 'http://localhost:3000/common-cents/categories';
public constructor(private readonly http: HttpService) {
void this.fetchCategories();
}
public async fetchCategories(): Promise<void> {
this.internalCategories.set(await this.http.get<Category[]>(this.categoryPath));
}
}
export interface Category {
id: string;
name: string;
}