26 lines
725 B
TypeScript
26 lines
725 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 categories = signal<Category[]>([]);
|
|
|
|
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;
|
|
}
|