Angular6 Typescript信号器:尽管客户端已连接到信号器集线器,但未获取任何事件
我已经用Web API和Angular UI创建了一个信号器中心 预期的结果是将Angular UI与SignalR hub连接,并且在服务器上发生的任何事件中,Angular客户端都应该收到相应事件名称的通知 角轮毂的代码为:Angular6 Typescript信号器:尽管客户端已连接到信号器集线器,但未获取任何事件,angular,typescript,signalr,signalr-hub,Angular,Typescript,Signalr,Signalr Hub,我已经用Web API和Angular UI创建了一个信号器中心 预期的结果是将Angular UI与SignalR hub连接,并且在服务器上发生的任何事件中,Angular客户端都应该收到相应事件名称的通知 角轮毂的代码为: public openChannel(url: string): void { this.hubConnection = $.hubConnection(url, {"useDefaultPath": true}); this.hubProxy =
public openChannel(url: string): void {
this.hubConnection = $.hubConnection(url, {"useDefaultPath": true});
this.hubProxy = this.hubConnection.createHubProxy('employeeHub');
this.hubConnection.logging = true;
**this.hubProxy.on('displayStatus', (channel: string) => {
console.log('worked', channel);
});**
this.hubConnection.start(this.options).done((data: any) => {
console.log('Connected to Processing Hub');
this.sendMessage();
}).catch((error: any) => {
console.log('Hub error -> ' + error);
});;
}
其调用方法为:
ngOnInit(): void {
this.getLGEData();
this._signalrService.openChannel('http://localhost/RealTimeNotify/Hubs');
}
它显示控制台消息“已连接到处理中心”,但当服务器端发生问题时,突出显示的代码不会显示任何控制台消息
当我们使用以下代码获取更新时,服务器端代码与jQuery配合良好:
$(function () {
// Proxy created on the fly
var emp = $.connection.employeeHub;
// Declare a function on the job hub so the server can invoke it
emp.client.displayStatus = function () {
getData();
};
// Start the connection
$.connection.hub.start();
getData();
});
如果在这方面需要更多信息,请告诉我
提前感谢。它自动工作,可能是因为缓存或其他原因,因为当我在同一页面中进行更改时,它们会反映在UI中 但直到我将其修改为:
this.hubProxy.on('displayStatus', (channel: string) => {
alert('abc');
console.log('worked', channel);
});
仅放置警报就可以刷新缓存或其他内容。角度方法打开('displayStatus',(通道:string)=>{
需要一个字符串参数,而jQuery方法根本不需要任何参数。您是否尝试将角度设置为无参数?