Overview
TheLibroListComponent provides administrators with a comprehensive view of all books in the system. It displays books in a table format with options to create, edit, and delete books.
Component Metadata
app-libro-list
Imports:
CommonModule- Angular common directivesRouterLink- Router navigation for edit links
./libro-list.html
Properties
libros
id: Book identifiertitulo: Book titleportada: Cover image URLanioPublicacion: Publication yeardisponible: Availability statusgenero: Genre object with id and nameautores: Array of author objects
Injected Services
- LibroService - Handles all book-related API operations
Lifecycle Hooks
ngOnInit
Methods
cargarLibros
LibroService and populates the libros array:
- On success: Updates
libroswith the response data and logs to console - On error: Logs error message to console
eliminarLibro
- Displays confirmation dialog “¿Estás seguro de eliminar este libro?”
- If confirmed, calls
LibroService.delete()with the book ID - On success:
- Reloads the book list by calling
cargarLibros() - Shows success alert “Libro eliminado correctamente”
- Reloads the book list by calling
- On error:
- Logs error to console
- Shows error alert “No se pudo eliminar el libro.”
id- The numeric ID of the book to delete
Template Features
The component displays books in a table with the following columns:Full Source Code
Related Components
- LibroFormComponent - Create and edit books
- CatalogoComponent - User view of book catalog
Related Services
- LibroService - Book CRUD operations
Related Models
- Libro - Book data structure