Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
No se pueden resolver todos los parámetros para AuthService en Angular

Estoy tratando de iniciar mi aplicación angular y recibo este error a continuación por alguna razón. Intenté eliminar el proveedor de servicios de autenticación de mi componente y eliminar también el servicio de autenticación de mi contratista dentro de mi componente, pero nada cambió... No puedo entender qué estoy haciendo mal y soy un principiante en angular.

El error:

 Can't resolve all parameters for AuthService: (?, ?, [object Object]).

Mi componente:

 import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { AuthService } from '../../Services/auth.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.css'], providers: [AuthService] }) export class LoginComponent { isUserLoggedIn: boolean; emailAddress: string; password: string; invalidLogin: boolean; invalidText: string; constructor(private authService: AuthService, private router: Router) { if (authService.getCurrentUser() != null) { router.navigate(['/home']); } } login() { if (!this.authService.login(this.emailAddress.toString(), this.password.toString())) { this.invalidLogin = true; this.invalidText = "Wrong Email Address or password"; } } }

mi servicio:

 import { Inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Router } from '@angular/router'; import { UserModel } from "../Models/UserModel"; export class AuthService { constructor(private router: Router, private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) {} login(email: string, password: string) { const headers = {'Content-Type': 'application/json', }; const body = { emailAddress: email, password: password }; let userLoggedIn: Boolean = false; this.http.post<any>(this.baseUrl + "Api/Login", body, { headers }).subscribe(response => { if (response.username != null) { let user: UserModel user = response; this.router.navigate(['/home']); this.saveUserToLocalStorage(user); userLoggedIn = true } }, error => console.error(error)); return userLoggedIn; } saveUserToLocalStorage(loggedInUser: UserModel) { sessionStorage.setItem("loggedInUser", JSON.stringify(loggedInUser)); } getCurrentUser() { return sessionStorage.getItem("loggedInUser") } logout() { sessionStorage.removeItem("loggedInUser") this.router.navigate(['']) } createUser(userData: UserModel) {} sendResetPasswordEmail() {} }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Creo que esto se debe a que usa Router en su constructor, intente hacer esto

 constructor(private readonly injector: Injector, ...) {} public get router(): Router { return this.injector.get(Router); }
about 4 years ago · Juan Pablo Isaza Report

0

Encontré cuál era el problema. Tuve que marcar mi clase de servicio como @Injectable()

Como esto:

 @Injectable() export class SchoolService { ... }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!