Overview
TheAutorListComponent provides administrators with a view of all authors in the system. It allows creating new authors, editing existing ones, and deleting authors that are not associated with any books.
Component Metadata
app-autor-list
Imports:
CommonModule- Angular common directivesRouterLink- Router navigation for creating and editing
./autor-list.html
Properties
autores
id: Author identifiernombre: Author nameurlFoto: Optional photo URL
Injected Services
- AutorService - Handles all author-related API operations
Lifecycle Hooks
ngOnInit
Methods
cargarAutores
AutorService and populates the autores array:
- On success: Updates
autoresarray and logs the data to console - On error: Logs error message to console with prefix “Error al cargar autores:”
eliminarAutor
- Displays confirmation dialog “¿Estás seguro de eliminar este autor?”
- If confirmed, calls
AutorService.delete()with the author ID - On success:
- Reloads the author list by calling
cargarAutores()
- Reloads the author list by calling
- On error:
- Logs error to console
- Shows error alert “No se pudo eliminar el autor (quizás tiene libros asociados).”
id- The numeric ID of the author to delete
Full Source Code
Related Components
- AutorFormComponent - Create and edit authors
- LibroFormComponent - Associates authors with books
Related Services
- AutorService - Author CRUD operations
Related Models
- Autor - Author data structure