Skip to main content

Overview

The LibroListComponent 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

Selector: app-libro-list Imports:
  • CommonModule - Angular common directives
  • RouterLink - Router navigation for edit links
Template: ./libro-list.html

Properties

libros

Array containing all books in the system. Each book object includes:
  • id: Book identifier
  • titulo: Book title
  • portada: Cover image URL
  • anioPublicacion: Publication year
  • disponible: Availability status
  • genero: Genre object with id and name
  • autores: Array of author objects

Injected Services

  • LibroService - Handles all book-related API operations

Lifecycle Hooks

ngOnInit

Called when the component initializes. Immediately loads all books from the backend.

Methods

cargarLibros

Fetches all books from the LibroService and populates the libros array:
  • On success: Updates libros with the response data and logs to console
  • On error: Logs error message to console
This method is called on initialization and after deleting a book to refresh the list.

eliminarLibro

Deletes a book from the system:
  1. Displays confirmation dialog “¿Estás seguro de eliminar este libro?”
  2. If confirmed, calls LibroService.delete() with the book ID
  3. On success:
    • Reloads the book list by calling cargarLibros()
    • Shows success alert “Libro eliminado correctamente”
  4. On error:
    • Logs error to console
    • Shows error alert “No se pudo eliminar el libro.”
Parameters:
  • 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

  • Libro - Book data structure