angular-pubsub

A publisher/subscriber provider for AngularJS.

Module License: MIT

Added by: Sam Deering

GitHub

Repository

tjlav5/angular-pubsub

Stats

Stars: 4

Watchers: 4

Forks: 0

Author

TJ Lavelle
TJ Lavelle

Module Description

angular-pubsub

NPM version Build Status Coverage Status Dependencies Downloads

A publisher/subscribers service for AngularJS.

Currently relies on browserify. Roadmap will include a built file that can be loaded in an index and injected into an angular app without this requirement.

Example Usage

app.js

var myApp = angular.module('myApp', [])
          .provider('PubSub', require('angular-pubsub'));

greetingController.js

myApp.controller('GreetingController', ['$scope', 'PubSub', function($scope, PubSub) {

  var greet = function (newGreeting, oldGreeting) {
    $scope.greeting = newGreeting;
    // first run  --> newGreeting = 'Hello', oldGreeting = undefined
    // second run --> newGreeting = 'World', oldGreeting = 'Hello'
  };

  var uid = PubSub.subscribe('greeting', greet);

  $scope.$on('$destory', function () {
    PubSub.unsubscribe(uid);
  });

}]);

loginController.js

myApp.controller('HelloController', ['$scope', 'PubSub', function($scope, PubSub) {

  PubSub.publish('greeting', 'Hello');
  PubSub.publish('greeting', 'World');

}]);

Module stats last updated: 2015-06-08 00:24:06

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!