Last active
December 17, 2015 17:29
-
-
Save jtrussell/5646086 to your computer and use it in GitHub Desktop.
Service for sharing state across controllers. Supports a notion of baseline states that can be rolled back to. You can also set (and sync to) new baselines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myModule').factory('SharedMetaData', function(SharedState) { | |
return SharedState.init({ | |
what: 'Array Stuffs', | |
arr: [1,2,3,4] | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myModule').controller('SomeCtrl', function($scope, $q, SharedMetaData) { | |
$q.when(SharedMetaData()).then(function(smd) { | |
$scope.smd = smd; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myModule').controller('SomeCtrl', function($scope, $q, SharedMetaData) { | |
var deferred = $q.defer(); | |
deferred.promise.then(SharedMetaData.set); | |
$timeout(function() { | |
deferred.resolve({ | |
what: 'new array stuffs', | |
arr: ['a', 'b', 'd'] | |
}) | |
}, 5000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment