【发布时间】:2019-01-19 01:00:26
【问题描述】:
我正在使用服务结构,并且能够编译我的应用程序,但是当我连接到它时,我收到以下错误:
An unhandled exception occurred while processing the request.
NodeInvocationException: No provider for SignalService!
Error: No provider for SignalService!
signal.service.ts
import { Injectable, OnInit } from '@angular/core';
import { HubConnection } from '@aspnet/signalr';
import * as signalr from '@aspnet/signalr';
@Injectable()
export class SignalService implements OnInit {
private _aphub: HubConnection;
public aphub: HubConnection = this._aphub;
ngOnInit(): void {
this._aphub.on("connect", () => {
console.log("Connect invoked");
});
let p = this._aphub.start();
Promise.all([p])
.then(() => {
this.aphub = this._aphub;
})
.catch(reason => {
console.log(reason);
});
}
constructor() {
let options = {
transport: signalr.HttpTransportType.WebSockets
| signalr.HttpTransportType.LongPolling,
AccessTokenFactory: async () => {
// Get and return the access token.
// This function can return a JavaScript Promise if asynchronous
// logic is required to retrieve the access token.
}
};
let protocol = new signalr.JsonHubProtocol();
this._aphub = new signalr.HubConnectionBuilder()
.configureLogging(signalr.LogLevel.Trace).withUrl('/aphub', options)
.withHubProtocol(protocol).build();
}
}
应该很简单,建立集线器连接,设置至少一个on 事件并启动连接。
app.browser.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppModuleShared } from './app.shared.module';
import { AppComponent } from './components/app/app.component';
import { SignalService } from "./signal.service";
@NgModule({
bootstrap: [AppComponent],
imports: [
BrowserModule,
AppModuleShared
],
providers: [
{ provide: 'BASE_URL', useFactory: getBaseUrl },
SignalService
]
})
export class AppModule {
}
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}
从那里,我将服务添加到提供程序,这就是它所抱怨的并且一切都编译了 - 但它没有运行。
【问题讨论】:
标签: typescript signalr angular5 azure-service-fabric