How to access the value of a promise?

I’m looking at this example from Angular’s docs for $q but I think this probably applies to promises in general. The example below is copied verbatim from their docs with their comment included: promiseB = promiseA.then(function(result) { return result + 1; }); // promiseB will be resolved immediately after promiseA is resolved and its value … Read more

AngularJS : Initialize service with asynchronous data

I have an AngularJS service that I want to initialize with some asynchronous data. Something like this: myModule.service(‘MyService’, function($http) { var myData = null; $http.get(‘data.json’).success(function (data) { myData = data; }); return { setData: function (data) { myData = data; }, doStuff: function () { return myData.getSomeData(); } }; }); Obviously this won’t work because … Read more