错误静态注入器:StaticInjectorError(AppModule)[GameService-> HttpClient]

the*_*iak 5 angular angular-library

我在Angular中遇到一个库问题。我已经完成了一个库,在其中我用HttpClient询问API,但是当我尝试从该库GameService继续上一个类时,出现了一个问题,我收到:“错误静态注入器:StaticInjectorError(AppModule)[GameService-> HttpClient]” 。当我看到该消息时,我尝试将HttpModule导入我的应用程序中并添加提供程序HttpClient,但未进行任何更改。这是我的类库的代码:

import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { Game } from './model/game';
import { Observable } from 'rxjs';
import { EndPointGetterService } from '../utilities/end-point-getter.service';

@Injectable({
  providedIn: 'root'
})
export class GameService {

  private gameUrl = localStorage.getItem('endpoint') + '/Games';
  private headers: HttpHeaders;

  constructor(private http: HttpClient, private EPGetter: EndPointGetterService) {
    this.headers = new HttpHeaders({
      'Access-Control-Allow-Origin': 'http://localhost:4200',
      'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
      'Access-Control-Allow-Headers': '*',
    });
  }
  getStateGame(groupName: string): Observable<number> {
    return this.http.get<number>(this.EPGetter.getEndPointUrl() + '/Games/' + groupName + '/State', { headers: this.headers });
  }
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我的app.module.ts中包含以下内容:

import { HttpClientModule, HttpClient } from '@angular/common/http';
import { GameService } from '@oneroomic/oneroomlibrary';

@NgModule({
  declarations: [
    AppComponent,
    NavComponent,
    LockscreenComponent,
    SettingsComponent
  ],
  imports: [
    HttpClientModule,
  ],
  providers: [
    HttpClient,
    GameService
  ],
Run Code Online (Sandbox Code Playgroud)

这就是我注入GameService的方式:

constructor(
  private snackBar: MatSnackBar,
  private gameService: GameService
  ) {}
Run Code Online (Sandbox Code Playgroud)

the*_*iak 0

好吧,问题是我尝试在本地安装这个库,但是当我发布到 NPM 上时,它起作用了。显然,当我尝试在本地安装时出现了问题。