Skip to content

alettieri/angular-signalr-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

angular-signalr-service

Angular SignalR Service

Using the Service

  1. Require the service as part of your application module.
  2. Configure the hub name during the config cycle of your module.
  3. Subscribe to hub events (.on) and Invoke hub events (.invoke or .send).

Example usage

  ItemHubFactory.$inject = ['HubProxy'];
  function ItemHubFactory(HubProxy) {
     return new HubProxy('itemHub');
  }

  ItemsService.$inject = ['ItemHub'];
  function ItemsService(Hub) {
    var Factory = this;
    
    Factory.items = [];
    
    Factory.getItemsFromHub = function(){
      // Ask the hub for items
      Hub.invoke('getItems');
    };
    
    // Hub responds with items
    // Callcback function is wrapped in $apply by hub
    Hub.on('itemsSentFromHub', function(items){
    
      angular.each(items, function(item){
        Factory.items.push(item);
      });
    
    });
    
    
    return Factory;
  }

  ItemsController.$inject = ['ItemsService'];
  function ItemsController(ItemsService) {
    this.items = myService.items;
    myService.getItems();
  }
  
  angular.app('myapp', ['services.hub']).factory('ItemHub', ItemHubFactory).factory('ItemsService', ItemsService).controller('ItemsController', ItemsController);

About

Angular SignalR Service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published