Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

angular-pubsub

0.2.0 • Public • Published

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

install

npm i angular-pubsub

Downloadsweekly downloads

2

version

0.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability