Creation of side-menu.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { CategoryRestService } from '../rest-services/category/category.rest-service';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { Category } from '../rest-services/category/model/category';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CategoryService {
|
||||
private categoryRestService = inject(CategoryRestService);
|
||||
private categoriesSubject = new BehaviorSubject<Category[]>([]);
|
||||
|
||||
private get categories(): Category[] {
|
||||
return this.categoriesSubject.value;
|
||||
}
|
||||
|
||||
get categories$(): Observable<Category[]> {
|
||||
if (!this.categories?.length) {
|
||||
this.categoryRestService.getCategories()
|
||||
.then(categories => this.categoriesSubject.next(categories))
|
||||
.catch(error => console.error('An error occured while loading categories.', error));
|
||||
}
|
||||
return this.categoriesSubject.asObservable();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user