【发布时间】:2016-11-03 19:54:47
【问题描述】:
我有一个使用 JavaScriptServices ng2 入门工具包 (https://github.com/aspnet/JavaScriptServices) 创建的非常小而简单的应用程序。
我想连接到信号器集线器并尝试在服务中执行此操作。我正在尝试使用 jquery $.hubconnection 来执行此操作,但是我看到一条错误消息...
Exception: Call to Node module failed with error: Error: Uncaught (in promise): ReferenceError: $ is not defined
我知道这是因为找不到 jQuery 库。有谁知道我可能做错了什么?
我的服务的开始看起来是这样的......
import { Injectable, EventEmitter } from '@angular/core';
declare var $;
@Injectable()
export class SignalRService {
private proxy;
private proxyName: string = 'dateHub';
private connection;
public foodchanged: EventEmitter<any>;
public connectionEstablished: EventEmitter<Boolean>;
public connectionExists: Boolean;
constructor() {
this.foodchanged = new EventEmitter();
this.connectionEstablished = new EventEmitter<Boolean>();
this.connectionExists = false;
this.connection = $.hubConnection('http://localhost:5000/' + 'signalr/');
// this.proxy = this.connection.createHubProxy(this.proxyName);
// this.registerOnServerEvents();
// this.startConnection();
}
我的完整代码在 github https://github.com/bencameron00/Ng2JQueryHub
我真的很感谢这里的一些帮助。我很困。
谢谢
【问题讨论】: