Skip to main content

Overview

The RegistroComponent allows new users to create an account in the system. After successful registration, users are automatically redirected to the login page.

Component Metadata

Selector: app-registro Imports:
  • CommonModule - Angular common directives
  • ReactiveFormsModule - Reactive forms support
  • RouterLink - Router navigation
Template: ./registro.html

Properties

registroForm

Reactive form group containing username and password fields with validators:
  • username: Required, minimum 4 characters
  • password: Required, minimum 4 characters

mensajeError

Stores validation or registration error messages to display to the user.

isSuccess

Indicates whether registration was successful. When true, displays success message and hides the form.

Constructor Dependencies

  • FormBuilder - Creates reactive form controls
  • AuthService - Handles registration API calls
  • Router - Navigates to login after successful registration

Methods

onSubmit

Handles form submission and user registration:
  1. Validates the form is complete and meets requirements
  2. Extracts username and password from the form
  3. Calls AuthService.register() with the registration data
  4. On success:
    • Sets isSuccess to true
    • Clears any error messages
    • Waits 3 seconds, then redirects to /auth/login
  5. On error: Displays message “Error al registrar. Es posible que el usuario ya exista.”
Example usage in template:

Full Source Code