Question

My js code for Angular js won't work. In jQuery it works. In Angular I always get the connection state 4 for disconnect. The jQuery code works fine.

AngularJS:

vvApp.value("$", $);
vvApp.service("signalRSvc", function ($, $rootScope) {
    var proxy = null;

    var initialize = function () {

        connection = $.hubConnection();

        this.proxy = connection.createHubProxy("helloWorldHub");

        connection.start();

        this.proxy.on('sendGreeting', function (message) {
            $rootScope.$emit("sendGreeting", message);
        });
    };

    var sendRequest = function () {
        this.proxy.invoke('greatAll');
    };

    return {
        initialize: initialize,
        sendRequest: sendRequest
    };
});

function SignalRAngularCtrl($scope, signalRSvc, $rootScope) {

    $scope.greetAll = function () {
        signalRSvc.sendRequest();
    }

    signalRSvc.initialize();

}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top