Skip to content

Instantly share code, notes, and snippets.

@seyDoggy
Forked from joladev/state.js
Last active August 29, 2015 14:09
Show Gist options
  • Save seyDoggy/37b8e07e4d674d16eef6 to your computer and use it in GitHub Desktop.
Save seyDoggy/37b8e07e4d674d16eef6 to your computer and use it in GitHub Desktop.
angular.module('services', [])
.factory('State', function ($rootScope) {
'use strict';
var state;
var broadcast = function (state) {
$rootScope.$broadcast('State.Update', state);
};
var update = function (newState) {
state = newState;
broadcast(state);
};
var onUpdate = function ($scope, callback) {
$scope.$on('State.Update', function (newState) {
callback(newState);
});
};
return {
update: update,
state: state,
listen: onUpdate
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment