Skip to content

Instantly share code, notes, and snippets.

@gearsdigital
Forked from joladev/state.js
Created August 13, 2014 20:45
Show Gist options
  • Save gearsdigital/7cf0467572bf156c1c5f to your computer and use it in GitHub Desktop.
Save gearsdigital/7cf0467572bf156c1c5f 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: listen
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment