我有一个非常小而简单的应用程序,我是从JavaScriptServices ng2初学者工具包(https://github.com/aspnet/JavaScriptServices)创建的。
我想连接到signalr集线器,并试图在服务中这样做。我试图使用jquery $.hubconnection来完成这个任务,但是我看到了一个错误,它说.
异常:调用节点模块失败,错误: error: Uncaught (在承诺中):ReferenceError:$未定义
我知道这是因为找不到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();
}我的完整代码在https://github.com/bencameron00/Ng2JQueryHub的github上
我真的很想在这里提供一些帮助。我被困住了。
谢谢
发布于 2016-11-03 11:43:31
您需要在packge.json中添加"jquery":"2.2.0“,然后在命令中添加: npm i
然后
导入'jquery';
在你的页面上
现在$将起作用
发布于 2016-11-03 11:54:47
<body>
<app-root>Loading...</app-root>
<script src="assets/xx/jquery-xxx.min.js"></script>
</body>
declare var $: any;
@Component({})https://stackoverflow.com/questions/40399401
复制相似问题