我对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();
}