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
2 Hrs
24 Min
21 Seg

Event binding: keydown

7/71
Resources

What are keyboard events in programming?

Keyboard events are essential in user interaction with web applications, as they allow us to capture specific actions when the user presses keys on their keyboard. These events are particularly useful for improving the user experience by providing quick responses to their actions, such as auto-completion or the execution of quick commands.

What are the most commonly used keyboard events?

There are several types of keyboard events that you can handle in programming, among the most common ones are:

  • keydown: this event is triggered the moment the user presses a key. It is very useful to detect the action in real time and is one of the most used events.
  • keyup: It is triggered when the user releases a previously pressed key. It is useful to detect the completion of an action.
  • keypress: Although less used today, it is triggered when a key is pressed that produces an input value in the field, such as the letter and number keys.

How do keydown events work in JavaScript?

Let's look at an example of using the keydown event in a programming environment, using TypeScript and Angular as a case study. The following function handles the keydown event, managing to capture details such as which key was pressed and on which element the action was performed:

// Handler method for the Keydown eventkDownHandler(event: KeyboardEvent): void { const input: HTMLInputElement = event.target as HTMLInputElement; console.log(`Keypressed: ${event.key}`); console.log(`Current  valueof input: ${input.value}`);}

In this code, each time a key is pressed, the event will be captured and the key pressed and the current value of the field being typed in will be printed to console.

What is the difference between keydown and change events?

An interesting question is how keydown and change events differ from each other and in which situations it is more appropriate to use one or the other:

  • keydown: allows you to capture in real time every key the user presses. It is ideal for situations where you need to react immediately to user input. For example, when implementing keyboard shortcuts.

  • change: Only triggers when the user finishes editing a text field and performs a "blur" action (such as pressing Enter or clicking outside the field). It is not triggered with each key press, which makes it more appropriate for final validations after the user has completed an entry.

How to configure keyboard shortcuts in Angular?

Angular makes it easy to implement keyboard shortcuts, which allows developers to assign specific actions to key combinations. For example, you could set up a handler that is triggered only when a specific combination such as Shift + T is pressed:

// Setting up a Keydown event with keyboard shortcut@Component({ selector: 'app-root', template: `<input(keydown.Shift.T)="clickHandler()">`}`})export class AppComponent { clickHandler(): void { console.log('Keyboard shortcut executed!'); } }}

In this code, the clickHandler method will be executed only when the Shift + T key combination is detected in the input field, allowing advanced and optimized functionalities for users.

Properly exploring and handling keyboard events can significantly improve the real-time interaction and usability of your applications, allowing you to respond dynamically to user actions. By applying these techniques, you not only increase the interactivity of the application, but also provide an enriched and professional user experience. Keep practicing and exploring, the learning never ends!

Contributions 7

Questions 1

Sort by:

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

Para tener mi texto en tiempo real en mi pantalla, tuve que usar keyup en lugar de keydown

<input type="text" (keyup)="changeTextKeyboard($event)" />
<p>I'm the input content => {{ valueInput }}</p>
valueInput = '';

changeTextKeyboard(event: KeyboardEvent) {
  const elementInput = event.target as HTMLInputElement;
  this.valueInput = elementInput.value;
}

Cuanto tiempo sin saber del (keyup.enter), me pudo haber ahorrado trabajo en mis proyectos anteriores.

Un atajo muy bueno ese! `(shift.enter)="vaPaProd()"`
Excelente lo del atajo de teclado, se ocurren varias ideas para una aplicación.
Dejo mis notas de la clase ```html <input type="number" [value]="age" (change)="changeHandler($event)"> <input type="text" [value]="name" (change)="changeHandler($event)" >
<input type="text" [value]="item.name" (keydown)="keydownHandler($event)"> <input type="text" [value]="name" (keydown.shift.a)="keydownShortcut()"> ```  \  \<input type="number" \[value]="age"  (change)="changeHandler($event)">  \<input type="text" \[value]="name" (change)="changeHandler($event)" >  \
  \  \<input type="text" \[value]="item.name" (keydown)="keydownHandler($event)">  \   \<input type="text" \[value]="name" (keydown.shift.a)="keydownShortcut()">
💻Resumen de la clase y algunos extras: ![](https://static.platzi.com/media/user_upload/clase7-1-b8df88ab-ba4f-417e-a934-5fdb2c514638.jpg) ![](https://static.platzi.com/media/user_upload/clase7-2-60fccbc9-84b4-4521-9b86-9bd7c81f7cb3.jpg) ![](https://static.platzi.com/media/user_upload/clase7-3-bc088f66-532a-42e5-b828-7f8275c3cf39.jpg) ![](https://static.platzi.com/media/user_upload/clase7-4-cb4a9946-977b-48cb-bdb7-4e7558f220be.jpg) ![](https://static.platzi.com/media/user_upload/clase7-5-6c01a309-b72e-45bc-9d8a-fe6c473276d9.jpg) ![](https://static.platzi.com/media/user_upload/clase7-6-f05208c1-f9d4-4863-87ff-ca96d51b3815.jpg) ![](https://static.platzi.com/media/user_upload/clase7-7-3883e9b6-0c17-4e02-b552-54bf6faa3dd9.jpg) ![](https://static.platzi.com/media/user_upload/clase7-8-ed0abad7-8fc1-4d89-a273-55b7498e4fe0.jpg) ![](https://static.platzi.com/media/user_upload/clase7-9-edfaa9a2-d1d5-4f15-8b6c-43d74742ecfd.jpg) ![](https://static.platzi.com/media/user_upload/clase7-10-535ed867-e37e-418f-a5df-7ad09a9a58fc.jpg) ![](https://static.platzi.com/media/user_upload/clase7-11-896f1018-aac1-44d8-a83e-2ed54064bf45.jpg) ![](https://static.platzi.com/media/user_upload/clase7-12-54b7f5ae-7a68-428b-8a75-db7842caf07c.jpg) ![](https://static.platzi.com/media/user_upload/clase7-13-a3a7aca0-81da-4589-9f5d-d5d3c9eb5805.jpg) ![](https://static.platzi.com/media/user_upload/clase7-14-514e8157-abf5-4d6f-a772-7e6b2e170068.jpg) ![](https://static.platzi.com/media/user_upload/clase7-15-11620307-3509-4176-a8a3-d3c9feee46c8.jpg) ![](https://static.platzi.com/media/user_upload/clase7-16-d7a0ed2f-a7f6-4239-a3ee-1c972b72f90d.jpg) ![](https://static.platzi.com/media/user_upload/clase7-17-896ac2b2-64b7-4409-b913-6a866938e381.jpg) ![](https://static.platzi.com/media/user_upload/clase7-18-5807d882-079c-4f11-ba4b-f81ba0a8e1f8.jpg) ![](https://static.platzi.com/media/user_upload/clase7-19-502ef03d-d4ba-4393-8631-ed924d350533.jpg) ![](https://static.platzi.com/media/user_upload/clase7-20-33ed62dc-c981-4454-9880-ba0d9295314c.jpg) ![](https://static.platzi.com/media/user_upload/clase7-21-1fc1eb90-01aa-477e-b36f-3c67231e92df.jpg) ![](https://static.platzi.com/media/user_upload/clase7-22-3a7fd313-6431-4b0d-9bf6-b01c388f6b25.jpg)