Overview
TheBackendService is the main service for handling backend API operations in the Angular PWA Demo. It extends BaseService and implements OnInit, providing methods for logging, CSV/Excel file generation, and data retrieval from multiple backend technologies including .NET Core, Node.js, Spring Boot, and Django.
This service showcases Angular 21’s functional dependency injection pattern using the
inject() function instead of constructor-based injection.Service configuration
Dependencies
The service uses Angular 21’s functional injection:Injected using
inject(HttpClient) for making HTTP requestsInjected using
inject(ConfigService) for configuration valuesInjected using
inject(DestroyRef) for managing subscriptions lifecycleCommon methods
_GetWebApiAppVersion
Retrieves the .NET Core Web API application version.Observable<string> containing the API version.
Usage example:
_GetASPNETCoreCppVersion
Retrieves the ASP.NET Core C++ entry point version.Observable<string> containing the C++ API version.
SetLog
Logs application events to the backend server.The title of the page where the log originated
The log message to record
The type of log entry (Info, Warning, Error)
CSV file generation
getCSVLink
Retrieves a link to a generated CSV file.Observable<string> containing the CSV file URL.
getInformeRemotoCSV
Generates a CSV report from the .NET Core backend.Observable<string> containing the CSV data.
getInformeRemotoCSV_STAT
Generates a statistical CSV report from cached data.Observable<string> containing the statistical CSV data.
_SetSTATPieCache
Caches statistical pie chart data on the backend.The base URL prefix for the API endpoint
getInformeRemotoCSV_NodeJS
Generates a CSV report from the Node.js backend.Observable<string> containing the CSV data from Node.js.
Excel file generation
getLogRemoto
Retrieves log entries from the .NET Core backend.Search criteria object containing date range and filters
Observable<LogEntry[]> containing the log entries.
Real-world usage:
getLogRemotoNodeJS
Retrieves log entries from the Node.js backend.Observable<string> containing JSON log data from Node.js.
Usage example:
getLogRemotoSprinbBootJava
Retrieves log entries from the Spring Boot (Java) backend.Observable<string> containing JSON log data from Spring Boot.
getPersonsSprinbBootJava
Retrieves person records from the Spring Boot backend.Observable<string> containing JSON person data.
getLogRemotoDjangoPython
Retrieves log entries from the Django (Python) backend.Observable<string> containing JSON log data from Django.
getInformeExcel
Generates an Excel file from the .NET Core backend.Search criteria for the Excel report
Observable<string> containing the Excel file name.
Real-world usage:
getPersonsDjangoPython
Retrieves person records from the Django backend.Observable<string> containing JSON person data from Django.
getLogStatGET
Retrieves statistical log data from the .NET Core backend cache.Observable<string> containing JSON statistical data.
_SetSTATBarCache
Caches statistical bar chart data on the backend.The base URL prefix for the API endpoint
Angular 21 features
This service demonstrates several Angular 21 best practices:- Functional injection
- DestroyRef
- Lifecycle management
Uses
inject() function instead of constructor parameters:Multi-backend support
The service communicates with multiple backend technologies:.NET Core / C#
Primary backend for most operations including file generation and logging.
Node.js / JavaScript
Alternative backend for CSV and log data retrieval.
Spring Boot / Java
Backend for Java-based log and person data operations.
Django / Python
Backend for Python-based log and person data operations.
Best practices
Use takeUntilDestroyed
Always use
takeUntilDestroyed(this.destroyRef) for subscriptions to prevent memory leaks.Related services
- ConfigService - Provides configuration values and base URLs
- AlgorithmService - Handles algorithm-specific operations