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

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

No se trata de lo que quieres comprar, sino de quién quieres ser. Invierte en tu educación con el precio especial

Antes: $249

Currency
$209

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscríbete

Termina en:

12 Días
5 Hrs
28 Min
11 Seg

ngFor para objetos

12/71
Recursos

Aportes 25

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?


Este fue el código que use para lograr este resultado

<li
  [class.completed]="task.completed"
  *ngFor="let task of tasks(); index as i"
>
  <div class="view">
    <input
      class="toggle"
      type="checkbox"
      [checked]="task.completed"
      (click)="toggleChecked(i)"
    />
    <label>{{ task.title }}</label>
    <button class="destroy"></button>
  </div>
  <input class="edit" [value]="task.title" />
</li>
toggleChecked(index: number) {
  this.tasks.update((value) =>
    value.map((task, position) => {
      if (position === index)
        return {
          ...task,
          completed: !task.completed,
        };
      return task;
    })
  );
}
Tome el curso de React y para hacer esto mismo haces un tremendo chorizo solo para eliminar y agregar elementos y aquí se siente super intuitivo manipular el dom •**Event Binding**: (click)="clickHandler()" (Paréntesis para eventos) •**Property Binding**: \[disabled]="isDisabled" (Corchetes para propiedades) •**Interpolation**: {{ expression }} (Dobles llaves para interpolar valores) •**$event**: Representa el evento y se usa para pasar información sobre el evento al método que se ejecuta. **Me esta gustando demasiado Angular.**
```ts toggleChecked(index: number) { this.tasks.update(tasks => { tasks[index] && ( tasks[index].completed = !tasks[index].completed ) return tasks }) } ``````html <input class="toggle" type="checkbox" [checked]="task.completed" (change)="toggleChecked($index)" /> ```
![](https://static.platzi.com/media/user_upload/image-4a4c0e64-93bc-460c-9df4-c2e233e1f8b7.jpg)
  toggleChecked(index: number) {
    this.tasks.update((tasks) =>
      tasks.map((task, i) =>
        i === index ? { ...task, complete: !task.complete } : task
      )
    );
  }
Hice esto con algo de ayuda: ```jsx //home.component.html <section class="todoapp"> <header class="header">

My Day

All my tasks in one place

<input class="new-todo" placeholder="Type new todo" autofocus name="filterName" type="text" (keydown)="changeHandler($event)" onfocus="this.value=''" />
</header>
<section class="main">
  • <input class="toggle" type="checkbox" [checked]="task.completed" (change)="changeTaskStatus(i)" /> <label> {{ task.title }} </label> <button class="destroy" (click)="deleteTask(i)"></button>
    <input class="edit" value="Learn JavaScript" />
</section> <footer class="footer"> 0 item left <button class="clear-completed">Clear completed</button> </footer>
</section> //home.component.ts import { Component, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Task } from './../../models/task.model' @Component({ selector: 'app-home', standalone: true, imports: [CommonModule], templateUrl: './home.component.html', styleUrl: './home.component.css' }) export class HomeComponent { tasks = signal<Task[]>([ { id: Date.now(), title: 'Crear proyecto', completed: false, }, { id: Date.now(), title: 'Crear componentes', completed: false, }, { id: Date.now(), title: 'Crear interfaz', completed: false, }, ]) get incompleteTasks() { return this.tasks().filter(task => !task.completed); } get completeTasks() { return this.tasks().filter(task => !!task.completed); } changeHandler(event: KeyboardEvent) { const input = event.target as HTMLInputElement; if (event.key === 'Enter' && input.value.trim() !== '') { const newTask = input.value.trim() this.addTask(newTask); input.value = ''; } } addTask(title: string) { const newTask = { id: Date.now(), title, completed: false, } this.tasks.update((tasks) => [...tasks, newTask]); } deleteTask(index: number){ this.tasks.update((task) => task.filter((task, position) => position !== index )) } changeTaskStatus(index: number) { this.tasks.update((tasks) => tasks.map((task, i) => i === index ? { ...task, completed: !task.completed }: task ) ) } } ```
Comparto la pequeña solución que le di, recibo cualquier critica constructiva. `home.html` `<input class="toggle" type="checkbox" (change)="completedTask($event, i)" [checked]="task.completed"/>` `<label [ngClass]="{'completed': task.completed}"> {{ task.title }} </label>` `home.components` `completedTask(event: Event, index: number){  const checkbox = event.target as HTMLInputElement;    this.tasks.update((tasks) => {` ` tasks[index].completed = checkbox.checked;      return tasks;    ` ` });  ` `}`
Para el reto implemente el siguiente modelo: home.component.ts ```js checkHandler(event: Event, i: number){ const input = event.target as HTMLInputElement; let updateTask: Task = this.tasks()[i]; updateTask.completed = input.checked; this.tasks.update((tasks) => tasks.map((task,position) => { return position === i ? updateTask : task; })) console.log(this.tasks()); } ``` home.component.html ```js <input type="checkbox" class="toggle" (change)="checkHandler($event,i)"> ```
mmmm .... primer drawback con Angular. que pasa, si quiero reutilizar el methodo de `addTask` en otro componente? Como puedo "modularizar esta logica => agregar Task a un Array?
Esta es mi solución: HTLM: ```js
  • <input class="toggle" type="checkbox" [checked]="task.completed" (click)="toggleChecked(task)" /> <label>{{ task.title }}</label> <button class="destroy" (click)="deleteTask(i)"></button>
    <input class="edit" value="Buy a unicorn" />
  • ```TS: ```js toggleChecked(task: Task) { this.tasks.update((value) => value.map((item) => { if (item.id == task.id) { item.completed = !item.completed; } return item; }) ); } ```
    Esta es mi solucion HTML: \
  • \
    \<input class="toggle" type="checkbox" \[checked]="task.completed" (click)="toggleChecked(task)" /> \<label>{{ task.title }}\</label> \<button class="destroy" (click)="deleteTask(i)">\</button> \
    \<input class="edit" value="Buy a unicorn" /> \
  • TS: toggleChecked(*task*: Task) { this.tasks.update((*value*) => *value*.map((*item*) => { if (*item*.id == *task*.id) { *item*.completed = !*item*.completed; } return *item*; }) ); }
    Esta es mi solución. HTML: \
  • \
    \<input class="toggle" type="checkbox" \[checked]="task.completed" (click)="toggleChecked(task)" /> \<label>{{ task.title }}\</label> \<button class="destroy" (click)="deleteTask(i)">\</button> \
    \<input class="edit" value="Buy a unicorn" /> \
  • ```js
  • <input class="toggle" type="checkbox" [checked]="task.completed" (click)="toggleChecked(task)" /> <label>{{ task.title }}</label> <button class="destroy" (click)="deleteTask(i)"></button>
    <input class="edit" value="Buy a unicorn" />
  • ```TS: ```js toggleChecked(task: Task) { this.tasks.update((value) => value.map((item) => { if (item.id == task.id) { item.completed = !item.completed; } return item; }) ); } ``` toggleChecked(*task*: Task) { this.tasks.update((*value*) => *value*.map((*item*) => { if (*item*.id == *task*.id) { *item*.completed = !*item*.completed; } return *item*; }) ); }
    ![](https://static.platzi.com/media/user_upload/image-2838e6aa-891c-4873-8a35-a899d30ee747.jpg)
    ```html //home.component.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } ```\<input (change)="checkCompleted(i)" class="toggle" type="checkbox" />```html //home.component.html <input (change)="checkCompleted(i)" class="toggle" type="checkbox" /> ```
    ```js //home.component.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } //home.component.html <input (change)="checkCompleted(i)" class="toggle" type="checkbox" /> ```checkCompleted(index: number) {    console.log(this.tasks()\[index].completed);    if (this.tasks()\[index].completed) {      this.tasks()\[index].completed = false;    } else {      this.tasks()\[index].completed = true;    }  }
    ```js Se intento! :XD //home.component.html <input (change)="checkCompleted(i)" class="toggle" type="checkbox"/> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } ``````js ```
    ```js Se intento! :XD //home.component.html <input (change)="checkCompleted(i)" class="toggle" type="checkbox"/> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } ``````js Se intento! :XD // <input (change)="checkCompleted(i)" class="toggle" type="checkbox" /> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } ```Se intento! :XD //home.component.html \<input (change)="checkCompleted(i)" class="toggle" type="checkbox"/> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()\[index].completed); if (this.tasks()\[index].completed) { this.tasks()\[index].completed = false; } else { this.tasks()\[index].completed = true; } }
    ```js Se intento! :XD // <input (change)="checkCompleted(i)" class="toggle" type="checkbox" /> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()[index].completed); if (this.tasks()[index].completed) { this.tasks()[index].completed = false; } else { this.tasks()[index].completed = true; } } ```Se intento! :XD //home.component.html \<input (change)="checkCompleted(i)" class="toggle" type="checkbox"/> //home.componet.ts checkCompleted(index: number) { console.log(this.tasks()\[index].completed); if (this.tasks()\[index].completed) { this.tasks()\[index].completed = false; } else { this.tasks()\[index].completed = true; } }
    Se intento! :XD // \<input (change)="checkCompleted(i)" class="toggle" type="checkbox" /> //home.componet.ts checkCompleted(index: number) {    console.log(this.tasks()\[index].completed);    if (this.tasks()\[index].completed) {      this.tasks()\[index].completed = false;    } else {      this.tasks()\[index].completed = true;    }  }
    ```js completedTask(event:Event,index:number){ const input = event.target as HTMLInputElement this.tasks()[index].completed = input.checked this.tasks.update((tasks) => this.tasks()) } ```completedTask(event:Event,index:number){ const input = event.target as HTMLInputElement this.tasks()\[index].completed = input.checked this.tasks.update((tasks) => this.tasks()) }
    yo use este código para simpleficar la creación de un task nuevo. `createTask(title : string): Task {    return {      id: Date.now(),      title,      completed: false    }  }` `  tasks = signal<Task[]>([    this.createTask('Create project'),    this.createTask('Create component'),  ]);` `  changeHandler(event: Event) {    const input = event.target as HTMLInputElement;    const newTask : Task = this.createTask(input.value);    this.tasks.update(tasks => [...tasks, newTask]);  }` `  deleteTask(index: number) {    this.tasks.update(tasks => {      return tasks.filter((task, indexTask) => indexTask !== index);    });  }`

    ✅

    ```js
  • <input class="toggle" type="checkbox" (click)="completeTask(i)"/> <label>{{ task.title }}</label> <button class="destroy" (click)="deleteTask(i)"></button>
    <input class="edit" value="Buy a unicorn" />
  • ``` ```txt completeTask(index: number) { this.tasks.update((tasks) => tasks.map((task, position) => { if (position === index) { task.completed = !task.completed; } return task; }) ); } ```
    ![](https://static.platzi.com/media/user_upload/image-51a12d5b-e900-4ac1-a949-85fcba1d1963.jpg)