Conoce la importancia de los formularios para tu sitio web

1

Versiones de Angular Forms

2

驴Por qu茅 aprender Angular Forms?

3

Presentaci贸n del proyecto: tour por los formularios de Platzi Store

4

Novedades de Angular 10: c贸mo migrar proyectos de Angular 8 o 9 a la versi贸n 10

Primeros pasos con Angular Forms

5

Template Forms vs. Reactive Forms

6

Dominando el FormControl y sus estados

7

C贸mo usar inputs de texto y la importancia del type

8

Manejo y binding de selects y selects m煤ltiples

9

Manejo y binding de inputs radio y checkbox

10

Aplica validaciones a un FormControl

11

Integraci贸n y validaciones con CSS para mostrar errores

Descubre todas las validaciones de Angular Forms

12

Usando FormGroup para agrupar multiples campos

13

Reactive Forms con FormBuilder

14

Los 11 validadores de Angular (y expresiones regulares)

15

Manejando m煤ltiples FormsGroups

16

Usando componentes de Angular Material

17

Errores comunes de usabilidad en formularios

18

Validaciones personalizadas: mejorando nuestro formulario de registro

Implemeta validaciones avanzadas en PlatziStore

19

C贸mo hacer validaciones grupales en Angular Forms

20

Validaciones condicionadas y reactividad a variaciones en la UI

21

Proyecto: formulario para crear categor铆as de productos

22

Proyecto: conectando nuestro formulario y la API

23

Proyecto: subir im谩genes a Firebase Storage

24

Validaciones asincr贸nicas

25

PatchValue: crear vs. editar

26

Proyecto: creando el m茅todo de editar categor铆as

Construye formularios din谩micos conectando una API

27

Smart vs. dumb components: un patr贸n para dividir responsabilidades

28

Implementando smart y dumb components en PlatziStore

29

Proyecto: mejorando nuestro formulario de productos

30

Select din谩mico: carga opciones desde una API

31

Select din谩mico: trabajando con objetos

32

驴C贸mo crear campos on demand? Forms din谩micos con FormArray

Estrategias avanzadas y optimizaci贸n de formularios

33

Crea tu propia librer铆a de componentes con CVA o Control Value Accesor

34

Crea un buscador de gifs usando la API de Giphy

35

Optimiza un input de b煤squedas con RxJS y debounce

36

Examina la accesibilidad de tus formularios

37

Siguientes pasos en tu carrera de desarrollo web profesional con Angular

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
56 Min
5 Seg

Proyecto: formulario para crear categor铆as de productos

21/37
Resources

How to create the categories module for an Angular application?

Working with categories in an application is crucial to maintain order and facilitate user navigation. Creating a category module in Angular is not a complicated task, but it requires attention to certain technical details to ensure that it is functional and efficient. Here I'll walk you through the essential steps to build and manage a category module, from the folder structure to how to link it to the API.

What is the structure of the category module?

The categories module is organized as part of an administration system in your Angular application. This module handles category creation, editing and deletion, and is divided into two main components:

  • Categories Component: in charge of listing existing categories.
  • Category Form Component: Used for both creating and editing categories.

This structure is located inside the admin folder, specifically in the categories submodule.

How to build the form with Angular Forms?

One of the first steps is to implement the form for the categories, which consists of a name and an image.

  1. Import Angular Forms: Make sure to import the necessary elements from Angular Forms:

    import { FormBuilder, FormControl, Validators } from '@angular/forms';
  2. Injection into the constructor: declare the FormBuilder as private inside the component's constructor:

    constructor(private formBuilder: FormBuilder) {}
  3. Create the form: define the form using the FormBuilder in a private method:

    this.categoryForm = this.formBuilder.group({ name: ['', Validators.required], image: ['', Validators.required]});
  4. HTML Components: Structure the HTML with Angular Material for a more aesthetically pleasing interface:

    <form [formGroup]="categoryForm"> <mat-card> <mat-card-header> <mat-card-title>NewCategory</mat-card-title> </mat-card-header> <mat-card-content> <mat-form-field> <input matInput placeholder="Name" formControlName="name" required> <mat-error*ngIf="categoryForm.get('name').hasError('required')"> Name is required </mat-error> </mat-form-field> <mat-form-field> <input matInput placeholder="Image" formControlName="image" required> <mat-error*ngIf="categoryForm.get('image').hasError('required')"> Image is required </mat-error> </mat-form-field> </mat-card-content> <mat-card-actions> <button mat-button type="submit">Save</button> </mat-card-actions> </mat-card></form> </mat-card></form>.

How to connect the form to the API?

The next essential step is to connect the form to interact with the API.

  1. Configure routes: Use RouterLink in your application to reach the form from the category list:

    <button mat-button [routerLink]="['/categories/create']">CreateCategory</button>.
  2. Angular Service: Create a service that handles HTTP requests to your API. This way, you can send new or updated categories:

     {import { HttpClient } from '@angular/common/http';
    constructor(private http: HttpClient) {}
    createCategory(categoryData: { name: string; image: string }) { return this.http.post('your-api-url/categories', categoryData);}
  3. Execute the flow: finally execute the creation flow, making sure that the form data is correctly sent to the API endpoint.

With these steps, you have a solid foundation for the categories module in your Angular application. Keep exploring and improving the functionality to suit your specific needs. Remember that every step you take, even if it seems small, gives you experience and prepares you for more complex projects. keep going!

Contributions 3

Questions 0

Sort by:

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

Template

<form [formGroup]="form" (ngSubmit)="save()">
  <mat-card>
    <mat-card-header>
      <mat-card-title>Categor铆a</mat-card-title>
    </mat-card-header>
    <mat-card-content>
        <div class="row">
          <div class="col-xs">
            <mat-form-field>
              <mat-label>Nombre</mat-label>
              <input placeholder="Nombre" formControlName="name" matInput type="text">
              <div class="messages" *ngIf="nameField.touched && nameField.invalid">
                <mat-error *ngIf="nameField.hasError('required')">
                  Este campo es requerido
                </mat-error>
              </div>
            </mat-form-field>
          </div>
        </div>
        <div class="row">
          <div class="col-xs">
            <mat-form-field>
              <mat-label>Image</mat-label>
              <input placeholder="Image" formControlName="image" matInput type="text">
              <div class="messages" *ngIf="imageField.touched && imageField.invalid">
                <mat-error *ngIf="imageField.hasError('required')">
                  Este campo es requerido
                </mat-error>
              </div>
            </mat-form-field>
          </div>
        </div>
    </mat-card-content>
    <mat-card-actions>
      <button mat-raised-button type="submit">Guardar categor铆a</button>
    </mat-card-actions>
  </mat-card>

</form>

una peque帽a menci贸n a la correcci贸n al inicio se menciono FormControl y luego se lo cambio a FormGroup

Lo que est谩 en categories.component.ts que se muestra en el video no lo pongan. Se les debe haber pasado(minuto 1:14). Dejen ese archivo como estaba en el repositorio.