Home > Blockchain >  Angular 14: Error No suitable injection token for parameter 'userService' of class 'V
Angular 14: Error No suitable injection token for parameter 'userService' of class 'V

Time:10-18

Here, i'm facing error in the view-users component file in constructor parameter

No suitable injection token for parameter 'userService' of class 'ViewUsersComponent'. Consider using the @Inject decorator to specify an injection token. constructor(private userService: userService, private activatedRouted: ActivatedRoute) { } Cannot find name 'userService'. Did you mean 'UserService'?

export class ViewUsersComponent implements OnInit { 
      userId: any = '';
      activatedRoute: any = '';
    
    constructor(private userService: userService, private activatedRouted: ActivatedRoute) { } 
    
    ngOnInit(): void {
    
        this.activatedRoute.params.subscribe((data: { id: any; }) => {
          this.userId = data.id; 
        });
        
        this.userService.viewuser(this.userId).subscribe((data: any) => {
          console.log(data);
        });
        
      }
    
    }

CodePudding user response:

Try replacing this line in your constructor.

Instead of

private userService: userService

Try

private userService: UserService

And make sure you have @Injectable decorator present in the UserService

  • Related