Introducción a Angular y Fundamentos

1

Aprende Angular 17

2

Creando tu primer proyecto en Angular

3

Implementando estilos

4

Mostrando elementos

5

Property Binding en Angular

6

Event Binding: click y doble click

7

Event binding: keydown

8

Modelo de reactividad con Signals

9

Creando un Signal en Angular

Estructuras de control en Angular

10

Directivas de control

11

Uso de ngFor

12

ngFor para objetos

13

Update Tasks

14

Uso de ngIf

15

Uso de ngSwitch y ngSwitchDefault

16

Controlando un input

17

Manejo de formularios en Angular

Alistando tu aplicación para producción

18

Estilos al modo Angular

19

Clases en Angular

20

Editing mode

21

Estados compuestos con computed

22

Usando effect para localStorage

23

Uso de ngbuild

24

Despliegue con Firebase Hosting

25

Nueva sintaxis en Angular

26

Directivas @For, @switch

27

Migrando a la nueva sintaxis de Angular v17

Componentes Reutilizables y Comunicación

28

Construyendo un e-commerce en Angular

29

Componentes en Angular

30

Mostrando los componentes

31

Angular DevTools

32

Uso de Inputs en Angular

33

Uso de Outputs en Angular

34

Componentes para Producto

Ciclo de vida de los componentes

35

Ciclo de vida de componentes

36

Ciclo de vida de componentes: ngOnChanges

37

Ciclo de vida de componentes: ngOnInit

38

Detectando cambios en los inputs

39

Evitando memory leaks con ngDestroy

40

Audio player con ngAfterViewInit

41

Creando la página "about us" o "conócenos"

Mejorando la interfaz del producto

42

Creando componente de productos

43

Creando el Header

44

Creando el carrito de compras

45

Comunicación padre e hijo

46

Calculando el total con ngOnChanges

47

El problema del prop drilling

48

Reactividad con signals en servicios

49

Entendiendo la inyección de dependencias

Integración y Datos

50

Obteniendo datos una REST API

51

Importaciones cortas en Typescript

52

Pipes en Angular

53

Construyendo tu propio pipe

54

Utilizando librerías de JavaScript en Angular

55

Conociendo las directivas

56

Deployando un proyecto en Vercel

Enrutamiento y Navegación

57

Ruta 404

58

Uso del RouterLink

59

Vistas anidadas

60

Uso del RouterLinkActive

61

Detalle de cada producto

62

Obteniendo datos del producto

63

Galería de imagenes

64

Detalle de la galería

Perfeccionando tu e-commerce

65

Mostrando categorias desde la API

66

Url Params

67

LazyLoading y Code Splitting

68

Aplicando LazyLoading

69

Prefetching

70

Usando la nueva sintaxis de Angular 17

71

Lanzando tu aplicación a producción

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
10 Hrs
58 Min
30 Seg

Galería de imagenes

63/71
Resources

How to display additional elements in a product gallery?

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.

How to display a category as part of a product?

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.

Creating a model for the category

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;}

Incorporation to the product model

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;}

Displaying the category in the interface

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>

How to manage and display multiple images of a product?

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.

Implementing ngFor to iterate images

We 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>

How to set up the main image replacement functionality?

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.

Declaring and managing the cover image signal

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]; }}

Function to change the cover image

We define a function that will update the cover image when clicking on an image in the gallery:

changeCover(newImage: string) { this.cover = newImage;}

Implementation in the HTML.

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

Sort by:

Want to see more contributions, questions and answers from the community?

1. ```js export interface Product{ id: number, title: string, price: number, images: string[], creationAt: string, description: string, category: { creationAt: string, id: number, image: string, name: string, updatedAt: string } } ```export interface Product{    id: number,    title: string,    price: number,    images: string\[],    creationAt: string,    description: string,    category: {        creationAt: string,        id: number,        image: string,        name: string,        updatedAt: string    }}
Con la nueva sintaxis  `  
ecommerce
   
     
        @for (imagen of product()?.images; track product()) {          ecommerce        }     
   
`
Por qué la API ya no es la misma, ahora el atributo images es un string y no un array como en el video?
Para salir de dudas jeje, esta mal realizarlo de esta forma?? ps en mi caso me funciona de esta manera, pero en buenas practicas si estaria bien? ![](https://static.platzi.com/media/user_upload/image-f4992894-0682-469a-977b-e44c12c54c21.jpg)
Nueva sintaxis: \
        @for(image of product()?.images; track image){          \<img            alt="ecommerce"            class="object-cover object-center rounded border-2 border-gray-200"            \[src]="image"          />        }      \
```js
@for(image of product()?.images; track image){ ecommerce }
```
la API esta rota...
Una pregunta cuando se debe utilizar set en vez de update ya que normalmente a una señal yo le hago es update, ya set ni la uso por que mis variables les coloco siempre valor por defecto. muchas gracias