1

when i enable the constructor i am getting an error as:

Can't resolve all parameters for HomeComponent: (?). at present i commented. not able to understand the issue:

Homecomponent.ts :

import { Component } from "@angular/core";
import { FormControl } from "@angular/forms";
import { switchMap, startWith, catchError, tap } from "rxjs/operators";
import { of } from "rxjs";
import { GitHubService } from "./../github.service";

@Component({
  selector: "app-home",
  templateUrl: "./home.component.html",
  styleUrls: ["./home.component.scss"]
})
export class HomeComponent {
  search = new FormControl("");
  user$ = this.search.valueChanges.pipe(
    switchMap((value) =>
      this.service.getUser(value).pipe(
        tap(console.log),
        catchError(({ error }) => of(error.errorMessage))
      )
    ),
    startWith("")
  );

  //constructor(private service: GitHubService) {}
}

my GitHubService.ts:

import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { tap } from "rxjs/operators";

@Injectable({
  providedIn: "root"
})
export class GitHubService {
  constructor(private http: HttpClient) {}

  getUser(username: string) {
    return this.http
      .get(`https://api.github.com/users/${username}`)
      .pipe(tap((x) => console.log(x)));
  }
}

Live Demo

Freestyle09
  • 4,894
  • 8
  • 52
  • 83
user2024080
  • 1
  • 14
  • 56
  • 96

0 Answers0