Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-pubsub

ng-pubsub is an AngularJS module that simplifies the way the siblings scopes -or any two other pieces of code- talk each other.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ng-pubsub

ng-pubsub is an AngularJS module that simplifies the way the siblings scopes -or any two other pieces of code- talk each other. AngularJS gives you $emit to dispatch events from a scope to the top of its hierarchy, and $broadcast to dispatch them to the bottom, but no mechanism is given to do that with siblings scopes. ng-pubsub fixes this.

How to

The first step is to download the ng-pubsub script. You can do it cloning this repo:

$ git clone https://github.com/vermicida/ng-pubsub.git

Or via NPM:

$ npm install ng-pubsub

Once the library is downloaded, make sure you are referencing it in your index.html, just after the AngularJS library reference. The minified version is only recommended for a production environment.

<script src="./node_modules/ng-pubsub/ng-pubsub.js"></script>

You must inject the ng-pubsub dependency within your module setter:

angular.module("test", ["dahr.ng-pubsub"]);

To subscribe a scope to an event, just use the $subscribe function. An unsubscriber function is returned, so remember to keep it safe:

angular
  .module("test")
  .controller("sibling1", function($scope, $pubsub) {
    var unsubscribe = $pubsub.$subscribe("onMessagePublished", function(data) {
      alert(data.message);
    });
  }
);

Then, to publish data on that event use $publish:

angular
  .module("test")
  .controller("sibling2", function($scope, $pubsub) {
    $pubsub.$publish("onMessagePublished", {
      message: "Hi, world"
    });
  }
);

If you want to unsubscribe the scope from that event, just do the following:

unsubscribe();

License

Code released under the MIT license.

Keywords

FAQs

Package last updated on 08 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc