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
40 Min
31 Seg

Ciclo de vida de componentes: ngOnChanges

36/71
Resources

How to mount a component in an Angular page?

To work properly with components in Angular, it is necessary to follow certain steps to mount and configure each part. Below, we illustrate with an example how a component can be used in our application through the process of importing and configuring it on a page.

Step 1: Create the base HTML

Initially, it is important to structure the HTML of the page where you want to assemble the component. Here we create some paragraphs to give structure and separate elements visually:

<p>Paragraph1</p><p>Paragraph2</p><p>Paragraph3</p><p>Paragraph3</p>

Step 2: Assemble the component

Once the basic elements are ready, we proceed to integrate the desired component. Using the component selector, we can add it directly to the HTML:

<app-counter></app-counter>.

Step 3: Import the component

It is vital to make sure that the component is correctly imported. In Angular, one component must be known in the context of the other. This is done by importing the component into the module that will use it.

import { CounterComponent } from 'shared/components/counter.component';

Add it to the imports array of your module:

@NgModule({ imports: [ CounterComponent ],. ..})

How to use signals to handle dynamic changes?

The use of signals is crucial to handle dynamic data and monitor changes in the application in a reactive way.

Step 1: Create signals

First, initialize the signals needed for critical variables such as duration and message.

const durationSignal = signal(1000);const messageSignal = signal('Default message');

Step 2: Manipulating signals with events

With the signals created, methods are implemented to modify these signals using events, commonly through HTML inputs.

function changeDuration(event: Event) { const inputElement = event.target as HTMLInputElement; durationSignal.set(Number(inputElement.value));}
function changeMessage(event: Event) { const inputElement = event.target as HTMLInputElement; messageSignal.set(inputElement.value);}

Step 3: Create interactive inputs

These inputs connect to the signals and allow the user to interact and modify values:

<input type="number" [value]="durationSignal" (input)="changeDuration($event)"><input type="text" [value]="messageSignal" (input)="changeMessage($event)"> <input type="text" [value]="messageSignal" (input)="changeMessage($event)">

How to visualize and debug components in Angular?

Once everything is configured, visualize your component and its interactions in practice.

Step 1: Configure demo page

If the about page is the one where the app-counter component is displayed, make sure to render the new page properly:

// In the router moduleconst routes: Routes = [ { path: 'about', component: AboutComponent },. ..];

Step 2: Browsing results in the browser

After correctly configuring the page and components, observe the interaction from the browser. Use tools such as DevTools to debug each event in the lifecycle:

  1. On startup, the component's constructor is executed first.
  2. The ngOnChanges event is triggered whenever an input property changes.
  3. The console displays specific changes and their history, such as previous and current values.

Careful implementation of these steps allows for a rich and interactive experience in Angular applications, facilitating future development and component enhancements. Continue exploring and honing your Angular skills!

Contributions 5

Questions 0

Sort by:

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

Por si llegan a tener este inconveniente ERROR Error: NG0500: During hydration Angular expected \

but found \<input>. Simplemente quiten las etiquetas \

Espero que les sirva.

La interfaz `HTMLInputElement` proporciona propiedades y métodos especiales para manipular las opciones, el diseño y la presentación de los elementos [`<input>`](https://developer.mozilla.org/es/docs/Web/HTML/Element/input).
Detalles del change: SimpleChanges: * Valor actual y valor anterior: change proporciona tanto el valor nuevo como el valor anterior de las propiedades que han cambiado. * Primer valor transmitido: change incluye un atributo que indica si es la primera vez que se transmite un valor para esa propiedad.

Mi aporte ngOnChanges se activa (se llama automáticamente) en un componente de Angular cuando cambian las propiedades decoradas con @Input() que recibe desde su componente padre. **¿Cuándo exactamente se activa ngOnChanges?** 1. **Justo después de que Angular haya actualizado un @Input()** (es decir, en el ciclo de vida del componente, antes de ngOnInit() si es la primera vez). 2. **Cada vez que el valor de un @Input() cambia** (después de la creación inicial también). **SimpleChanges te muestra qué cambió** Es un objeto que contiene todas las propiedades @Input() que cambiaron, con: * currentValue: el nuevo valor * previousValue: el valor anterior * firstChange(): si es la primera vez que cambia