2017-01-09 12 views
1

私はangularjs(1.5.6)私は、次のライブラリを使用angularjs signalr - 解決サーバー方法

でSignalRを使用していくつかの困難を持っている: Https://github.com/JustMaier/angular-signalr-hub

I SignalRをサポートしている必要があり、次の工場を持っています。私のコントローラで

'use strict'; 
app.factory('commonFactory', commonFactory); 

commonFactory.$inject = ['$rootScope', 'Hub', '$log']; 

function commonFactory($rootScope, Hub, $log) { 
    var scope = $rootScope; 

    scope.hub = { 
     instance : {}, 
     isReady : false 
    }; 

    var _listeners = { 
     'login': function (message) { 
      $log.log(message); 
      $rootScope.$apply(); 
     } 
    }; 
    var _methods = ['connect', 'sendMessage']; 

    var _errorHandler = function (error) { 
     console.error(error); 
    }; 

    var _hub = new Hub('message', { methods: [] }) 
    .promise.done(function() { 
     _hub.listeners = _listeners; 
     _hub.methods = _methods; 
     _hub.errorHandler = _errorHandler; 

     scope.hub.isReady = true; 
     scope.hub.instance = _hub; 
    }); 
} 

、私は私の工場を使用します。

app.controller('loginController', loginController); 

loginController.$inject = ['$scope', 'commonFactory']; 

function loginController($scope, commonFactory) { 
    $scope.login = _login; 


    $scope.model = { 
     user : { 
      id : 1 
     } 
    } 

    function _login() { 
     commonFactory.hub.instance.connect($scope.model.user.id); 
    } 
} 

次の行にエラーがある: commonFactory.hub.instance.connect($ scope.model.user.id)。

それは言う:

commonFactory.hub.instance.connectは(C#で書かれた)サーバーのメソッドを解決するためにどのように機能

ない

インタフェース:

public interface IMessageHub 
{ 
    [HubMethodName("login")] 
    void Login(object message); 

    [HubMethodName("send")] 
    void Send(object message); 

    [HubMethodName("connect")] 
    void Connect(Guid userGuid); 

} 

ありがとうございます。

私はそれFIXEまし

答えて

0

は '厳格な使用';

app.factory( 'commonFactory'、commonFactory);

commonFactory。$ inject = ['$ rootScope'、 'Hub'、 '$ log'];

function commonFactory($ rootScope、Hub、$ log){ var scope = $ rootScope;

varインスタンス= { };

var hub = new Hub('message', { 
    listeners: { 
     'login': function (from, to, message) { 
      $log.log(message); 
      $rootScope.$apply();; 
     } 
    }, 

    //server side methods 
    methods: ['connect', 'sendMessage'], 

    //handle connection error 
    errorHandler: function (error) { 
     console.error(error); 
    } 
}); 

var _login = function (userGuid) { 
    hub.promise.done(function() { 
     hub.login(userGuid); //Calling a server method 
    }); 
}; 

instance.login = _login;  return instance; } 
関連する問題