LoginPage Component
TheLoginPage component provides the user interface for authentication in the Karma Ecommerce application. It handles user login by calling the UsuarioRepository service and displaying authentication results.
Location
Component Code
- TypeScript
- HTML Template
@Component Decorator
The component is configured with the following metadata:| Property | Value | Description |
|---|---|---|
selector | 'app-login-page' | HTML selector for the component |
imports | [] | Standalone component with no additional imports |
templateUrl | './login-page.html' | Path to the HTML template |
styleUrl | './login-page.css' | Path to the component styles |
Properties
authService
Methods
ngOnInit()
ngOnChanges()
login()
usuario(string) - Username for authenticationcontrasena(string) - Password for authentication
loginUsuario()- Calls the repository method that returns an Observablepipe()- Chains RxJS operatorstap()- Side effect operator that:- Logs the user object to console
- Displays success alert if user is authenticated
- Displays error alert if authentication fails
subscribe()- Activates the observable stream
- On success: Displays “usuario y contraseña correctos!”
- On failure: Displays “usuario o contraseña incorrectos”
- Logs the user object to the browser console
Dependency Injection
The component uses Angular’s dependency injection to inject theUsuarioRepository:
Routing Configuration
The LoginPage is configured as the root route inapp.routes.ts:
- Path:
/(root route) - Component: LoginPage
- Access: Direct navigation to the application root
Related Components
- RegisterPage - User registration page
- UsuarioRepository - Authentication repository
- AuthService - Authentication service
Usage Notes
- The component currently uses hardcoded credentials in the template for testing
- Authentication results are displayed using browser alerts
- The component implements the
OnInitinterface but has no initialization logic - No error handling is implemented in the login method
- The component follows Angular standalone component architecture
