https://github.com/patrickjs/angular-event-emitter
Event emitters for AngularJS
https://github.com/patrickjs/angular-event-emitter
Last synced: 8 months ago
JSON representation
Event emitters for AngularJS
- Host: GitHub
- URL: https://github.com/patrickjs/angular-event-emitter
- Owner: PatrickJS
- Created: 2013-12-20T03:23:29.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-19T03:11:59.000Z (over 11 years ago)
- Last Synced: 2025-05-08T00:04:55.220Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 207 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
angular-event-emitter
=====================
Event emitters for AngularJS
#How do I add this to my project?
You can download angular-event-emitter by:
* (prefered) Using bower and running `bower install angular-event-emitter --save`
* Using npm and running `npm install angular-event-emitter --save`
* Downloading it manually by clicking [here to download development unminified version](https://raw.github.com/gdi2290/angular-event-emitter/master/angular-event-emitter.js)
````html
Add more
This is section #{{ toggle }}
angular.module('YOUR_APP', [
'ngEventEmitter' // you may also use 'angular-event-emitter'
])
.controller('MainController', function($scope, $once, $on, $emit) {
$once('event', function(event, args) {
console.log('$once ', args);
});
$on('event', function(event, args) {
console.log('$on', args);
});
$scope.add = function(collection) {
var lastIndex = collection.length-1;
var count = collection[lastIndex];
collection.push(count+1);
};
$scope.toggle = true;
$scope.toggles = [1,2,3];
// $scope.triggerArgs = function() {};
$scope.callback = function(value) {
$emit('event', 'trigger event');
console.log('callback ', arguments);
};
})
.directive('toggleSection', function($animate) {
return function(scope, element, attrs) {
var toggle = true;
scope.$onRootScope('event:'+(attrs.ngOn || attrs.toggleSection), function(ev,num) {
toggle = !toggle;
var toggleClass = (toggle) ? 'removeClass' : 'addClass';
$animate[toggleClass](element, 'ng-hide');
$animate[toggleClass](element, 'ng-show');
});
}
});
````