Introducción a Angular y Fundamentos
Aprende Angular 17
Creando tu primer proyecto en Angular
Implementando estilos
Mostrando elementos
Property Binding en Angular
Event Binding: click y doble click
Event binding: keydown
Modelo de reactividad con Signals
Creando un Signal en Angular
Estructuras de control en Angular
Directivas de control
Uso de ngFor
ngFor para objetos
Update Tasks
Uso de ngIf
Uso de ngSwitch y ngSwitchDefault
Controlando un input
Manejo de formularios en Angular
Alistando tu aplicación para producción
Estilos al modo Angular
Clases en Angular
Editing mode
Estados compuestos con computed
Usando effect para localStorage
Uso de ngbuild
Despliegue con Firebase Hosting
Nueva sintaxis en Angular
Directivas @For, @switch
Migrando a la nueva sintaxis de Angular v17
Componentes Reutilizables y Comunicación
Construyendo un e-commerce en Angular
Componentes en Angular
Mostrando los componentes
Angular DevTools
Uso de Inputs en Angular
Uso de Outputs en Angular
Componentes para Producto
Ciclo de vida de los componentes
Ciclo de vida de componentes
Ciclo de vida de componentes: ngOnChanges
Ciclo de vida de componentes: ngOnInit
Detectando cambios en los inputs
Evitando memory leaks con ngDestroy
Audio player con ngAfterViewInit
Creando la página "about us" o "conócenos"
Mejorando la interfaz del producto
Creando componente de productos
Creando el Header
Creando el carrito de compras
Comunicación padre e hijo
Calculando el total con ngOnChanges
El problema del prop drilling
Reactividad con signals en servicios
Entendiendo la inyección de dependencias
Integración y Datos
Obteniendo datos una REST API
Importaciones cortas en Typescript
Pipes en Angular
Construyendo tu propio pipe
Utilizando librerías de JavaScript en Angular
Conociendo las directivas
Deployando un proyecto en Vercel
Enrutamiento y Navegación
Ruta 404
Uso del RouterLink
Vistas anidadas
Uso del RouterLinkActive
Detalle de cada producto
Obteniendo datos del producto
Galería de imagenes
Detalle de la galería
Perfeccionando tu e-commerce
Mostrando categorias desde la API
Url Params
LazyLoading y Code Splitting
Aplicando LazyLoading
Prefetching
Usando la nueva sintaxis de Angular 17
Lanzando tu aplicación a producción
You don't have access to this class
Keep learning! Join and start boosting your career
When developing a product gallery, it is essential not only to display images, but also to offer interactive functionalities that enrich the user experience. Next, we will explore how to handle additional elements, such as categories and multiple images, using Angular, a popular web development platform.
To enrich the information presented, it is essential to display additional details, such as the product's category. If a product has a category defined as a nested object, we will first need to map these details into our data model.
Before displaying the category details, it is important to define a model for it. This model will contain the attributes id
, name
and image
:
// category.model.tsexport interface Category { id: number; name: string; image: string;}
Next, we include this model inside the product model, specifying that a product can have a linked category:
// product.model.tsexport interface Product { id: number; name: string; images: string[]; category?: Category;}
Finally, we can use the mapped object to display the category name in uppercase, using an Angular pipe
:
<!-- product.component.html --><div>{{ product.category?.name | uppercase }}</div>
It is common for products to have more than one image to show different angles or features. Angular makes it easy to manage these images thanks to directives like ngFor
.
ngFor
to iterate imagesWe employ ngFor
to iterate over all the images in the array and display them dynamically in the gallery:
<div*ngFor="let image of product.images"> <img [src]="image" (click)="changeCover(image)"></div>
By clicking on any image in the gallery, we should be able to set it as the main image of the product. For this, let's create a signal (or signal
) that stores this cover image.
First, we declare a signal for the cover image in the product detail component:
// product-detail.component.tscover: string = '';
ngOnInit() { if (product.images && product.images.length > 0) { this.cover = product.images[0]; }}
We define a function that will update the cover image when clicking on an image in the gallery:
changeCover(newImage: string) { this.cover = newImage;}
We ensure that the first image displayed is the initial cover and that gallery images can change it:
<img [src]="cover" alt="Product cover"><div*ngFor="let image of product.images"> <img [src]="image" (click)="changeCover(image)"></div>
With these steps, we achieve an interactive gallery that not only displays multiple images of a product, but also allows you to dynamically change the cover image with a simple click. This functionality significantly enhances the user experience in an online store. As you learn and explore more about Angular, identify areas where you can apply this type of functionality to create more interactive and intuitive experiences. Be sure to experiment and discover new possibilities with Angular!
Contributions 8
Questions 2
✅
Want to see more contributions, questions and answers from the community?