Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including angular-pubsub with all npm packages installed. Try it out:

var angularPubsub = require("angular-pubsub")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

angular-pubsub v0.2.0

A publisher/subscriber service for AngularJS

angular-pubsub

NPM version Build Status Coverage Status Dependencies

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

}]);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free