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

angular-events

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-events

Very simple angularjs (angular 1) events

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

angular-events

Only two methods: .broadcast() and .on(), without native upwards(broadcast)/downwards(emit) logic and scope mess.

Angular version note

Works great with Angular 1.6.*, should work with lower versions as well.

Install

npm install angular-events --save

Include script

<script src="node_modules/ng-events/dist/ng-events.min.js">

Be sure path to node_modules is correct

Add dependency

angular.module('yourApp', ['ngEvents']);

Usage

Broadcast event

angular.module('yourApp').factory('Service1', ['$events', function($events) {

  $events.broadcast('SOMETHING_HAPPENED');
  
}]);

Listen to event

angular.module('yourApp').factory('Service2', ['$events', function($events) {

  $events.on('SOMETHING_HAPPENED', function() {
  
    console.log('Something happened, got it!');
    
  })
  
}]);

Advanced stuff

Passing data

You can also pass data when broadcasting:

  $events.broadcast('SOMETHING_HAPPENED', {info: 'some info'});

and get it:

  $events.on('SOMETHING_HAPPENED', function(data) {
  
    console.log('Something happened, got it! And here is what we know: ' + data.info);
    
  });
Subscribe / listen to multiple events
  $events.on(['SOMETHING_HAPPENED', 'SOMETHING_ANOTHER_HAPPENED'], function() {
  
    console.log('We know that something or something another happened. And it should not bother us that we do not know which specific event was fired (by design means)!');
    
  });
Set handler priority
$events.on('SOMETHING_HAPPENED', function ()
{

	console.log('this will have default priority 500');

});

$events.on('SOMETHING_HAPPENED', function ()
{

	console.log('this will have priority 1000');

}, 1000);


$events.on('SOMETHING_HAPPENED', function ()
{

	console.log('this will have priority 1001 (because push is used)');

});

$events.on('SOMETHING_HAPPENED', function ()
{

	console.log('this should be shown second and...');

}, 20);

$events.on('SOMETHING_HAPPENED', function ()
{

	console.log('This should be shown first and...');

}, 10);

Keywords

FAQs

Package last updated on 13 May 2017

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