Problem when trying to connect to a Signalr+Angularjs Hub

Asked

Viewed 123 times

5

I have a little project with WebApi,SignalR and Angularjs where I do some queries and inserts in real time. Everything works fine when I start the file index.html right when running the application, but if I try to run the file individually, even with the application circling I have the following error:

hub is Undefined

The error starts in this line of my controller:

hub.client.addItem = function(item) {
   $scope.comments.push(item);
   $scope.$apply();
}

And I define the hub at the beginning, that way:

 var hub = $.connection.myHub; 

Working Hub(Running directly on the VS server): inserir a descrição da imagem aqui


Hub not working(Running on a Python server):

inserir a descrição da imagem aqui

1 answer

2


I solved the problem by referencing the hub path before start.

var hub = $.connection.myHub;
$.connection.hub.url = "http://localhost:5702/signalr";
$.connection.hub.start().done(function() {
  console.log("Conectado");
}).fail(function(error) {
  console.log('Invocation of start failed. Error: ' + error)
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.