toSignal via Gemini

This commit is contained in:
2026-08-18 07:55:54 +00:00
parent 59eb45da96
commit 993f83c786
350 changed files with 6231 additions and 9801 deletions
+9 -11
View File
@@ -1,5 +1,5 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { HttpClient, HttpHeaders, httpResource, HttpResourceRef } from '@angular/common/http';
import { Injectable, Signal, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
@@ -19,17 +19,15 @@ export class PrinterService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: string | null): Observable<Printer> {
const getUrl: string = id === null ? url : `${url}/${id}`;
return this.http
.get<Printer>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Printer>;
get(id: Signal<string | null> | string | null): HttpResourceRef<Printer | undefined> {
return httpResource<Printer>(() => {
const idVal = typeof id === 'function' ? id() : id;
return idVal === null || idVal === undefined ? url : `${url}/${idVal}`;
});
}
list(): Observable<Printer[]> {
return this.http
.get<Printer[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Printer[]>;
list(): HttpResourceRef<Printer[] | undefined> {
return httpResource<Printer[]>(() => `${url}/list`);
}
save(printer: Printer): Observable<Printer> {