Overview
TheGeneroListComponent provides administrators with a view of all literary genres in the system. It allows creating new genres, editing existing ones, and deleting genres that are not associated with any books.
Component Metadata
app-genero-list
Imports:
CommonModule- Angular common directivesRouterLink- Router navigation for creating and editing
./genero-list.html
Properties
generos
id: Genre identifiernombre: Genre name (e.g., “Ficción”, “Ciencia Ficción”, “Romance”)
Injected Services
- GeneroService - Handles all genre-related API operations
Lifecycle Hooks
ngOnInit
Methods
cargarGeneros
GeneroService and populates the generos array:
- On success: Updates
generosarray and logs the data to console - On error: Logs error message to console with prefix “Error al cargar géneros:”
eliminarGenero
- Displays confirmation dialog “¿Estás seguro de eliminar este género?”
- If confirmed, calls
GeneroService.delete()with the genre ID - On success:
- Reloads the genre list by calling
cargarGeneros() - Shows success alert “Género eliminado correctamente”
- Reloads the genre list by calling
- On error:
- Logs error to console
- Shows error alert “No se pudo eliminar el género. Es probable que existan libros asociados a él.”
id- The numeric ID of the genre to delete
Full Source Code
Related Components
- GeneroFormComponent - Create and edit genres
- LibroFormComponent - Associates genres with books
Related Services
- GeneroService - Genre CRUD operations
Related Models
- Genero - Genre data structure