Wooow hasta el momento el curso esta excelente. Me encanta que hayan mostrando ejemplos prácticos con ngOnDestroy() ngViewAfterInit(), constructor(), ngOnInit() y ahora ngOnChanges, sin duda el curso esta de lo mejor 💚
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
To master Angular, it is critical to understand how components communicate with each other. In this case, the architecture consists of three base nodes, with ListComponent
functioning as a master node. This master node manages communication between components through inputs
and outputs
.
ListComponent
uses ng-for
to render multiple products.ProductComponent
sends a notification to ListComponent
through an output
.ListComponent
not only maintains a reference to the products in the cart, but also notifies HeaderComponent
of changes via input
.HeaderComponent
updates the shopping cart in the application side menu.This flow ensures a reactive and efficient interaction between the components. An additional challenge has been to improve the visual appearance and calculate the total of the cart list.
For a better visual presentation, simple enhancements using flex
were used to organize the product image, title and price in a neater and clearer format. However, the final important goal is to show the total of the products in the cart. This can be achieved by following these steps:
By proposing a method inside HeaderComponent
called CalculateTotal
, you can accumulate the price of all the products in the cart. An efficient way to do this is using the reduce
method in JavaScript.
calculateTotal() { return this.cart.reduce((total, product) => total + product.price, 0);}
Although string interpolation in Angular allows you to call functions directly in the template, doing so can affect the performance of the application, unless the function is a signAll
. To avoid performance issues:
card
is not a signal and cannot be used directly as computed
, it is important to manage how the total is recalculated with new data.Adopt best practices using ngOnChanges
to recalculate the total when there are changes in the input
:
total
variable as a signal:total = signAll(0);
ngOnChanges
: Check for changes in the input
.ngOnChanges(changes: SimpleChanges) { if (changes.cart) { this.total.set(this.calculateTotal()); } }}
cart
recalculates the total
.With this approach, Angular optimizes component interaction and improves performance by avoiding direct functions inside the template. In addition, encouraging these advanced practices ensures clean, efficient and scalable code. Remember that programming is a vast world and there are always new techniques and strategies to learn, so keep exploring and expanding your skills!
Contributions 21
Questions 2
Wooow hasta el momento el curso esta excelente. Me encanta que hayan mostrando ejemplos prácticos con ngOnDestroy() ngViewAfterInit(), constructor(), ngOnInit() y ahora ngOnChanges, sin duda el curso esta de lo mejor 💚
Total {{total() }}
``` ✅ De esta manera podríamos hacer la implementación con un input con signals. Esto está documentado en la página de Angular [Accepting Data with Input Properties](https://angular.dev/guide/components/inputs)\
\{{ product.title }}\
\{{ product.price | currency:'Bs.':'symbol':'1.2-2' }}\
\{{ product.title }}\
\{{ product.price | currency:'Bs.':'symbol':'1.2-2' }}\
\Total:\
\{{ total() | currency:'Bs.':'symbol':'1.2-2' }}\
\${{product.price}}\
\Products on the cart
Producto: {{cart.title}}
Precio: ${{cart.price}}
✅
Want to see more contributions, questions and answers from the community?