NullInjectorError: No provider for HubService

NullInjectorError: No provider for HubService

我开始学习 signalr 和 angular,我想创建一个可以使用 signalr 与浏览器对话的应用程序。 我在 angular 中使用 ngx-signalR-hubservice 与 signalr 应用程序通信。我创建了一个简单的服务来测试代码

import { Injectable } from '@angular/core';
import {
  HubService,
  Hub,
  HubSubscription,
  HubWrapper
} from 'ngx-signalR-hubservice';

@Injectable({providedIn: 'root'})
@Hub({hubName: 'DALHub'})
export class UserConnectionServiceService {
  private hubWrapper: HubWrapper;
  constructor(private hub: HubService) {
    this.hubWrapper = this.hub.register(this);
    this.hub.connect({url: 'http://localhost:10476/signalr'});
}
  async SaveKey() {
    await this.hubWrapper.invoke('SaveKey', 'yedidya', 'kfiry');
    console.log('awesome');
  }
  @HubSubscription()
  OK() {
    console.log('GOT IT');
  }
}

这是我的应用组件

import { NgModule } from '@angular/core';
import { HubService } from 'ngx-signalr-hubservice';

@NgModule({
  declarations: [
    AppComponent,
    SignUpComponent,
    LogInComponent
  ],
  imports: [
  ],
  providers: [HubService],
  bootstrap: [AppComponent]
})
export class AppModule {}

这是我使用我创建的服务的代码

import { Component, OnInit } from '@angular/core';
import {UserConnectionServiceService} from '../../Services/UserConnectionService/user-connection-service.service';

@Component({
  selector: 'app-sign-up',
  templateUrl: './sign-up.component.html',
  styleUrls: ['./sign-up.component.css']
})
export class SignUpComponent implements OnInit {
  public save(): void {
    this.hub.SaveKey();
  }
  constructor(private hub: UserConnectionServiceService) { }

  ngOnInit() {
  }

}

但是当我尝试 运行 它时(我使用 ng serve)我在浏览器中收到以下错误

ERROR Error: StaticInjectorError(AppModule)[SignUpComponent -> HubService]: StaticInjectorError(Platform: core)[SignUpComponent -> HubService]: NullInjectorError: No provider for HubService! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:979)

在 AppModule 中

 import { HubService } from 'ngx-signalr-hubservice'; 

在 UserConnectionServiceService 中:

import {
  HubService,
  Hub,
  HubSubscription,
  HubWrapper
} from 'ngx-signalR-hubservice';

应该是ngx-signalr-hubservice吗?

我认为这是作者的错别字。这是 npm link:https://www.npmjs.com/package/ngx-signalr-hubservice