AngularJS与SignalR无法正常工作

时间:2014-02-28 17:48:27

标签: javascript jquery angularjs signalr

我对Angular js的js代码不起作用。在jQuery中它可以工作。 在Angular中,我总是得到connection state 4断开连接。 jQuery代码工作正常。

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();

}

0 个答案:

没有答案