For the subject matter, I found this SO post: Initialize service with asynchronous data
While this looks good, it is two years old and some of the references are out of date. Ex:
$http.get('url').success replaced with $http.get('url').then
Anyway, I have my model:
app.factory('User', function($http, $q) {
var myData = null;
var promise = $http.get('data.json').then(function (data) {
myData = data;
});
return {
promise: promise,
setData: function (data) {
myData = data;
},
doStuff: function () {
return myData.getSomeData();
}
};
});
and I need to share it across multiple controllers:
app.controller('controllerOne', function(User) {
// do stuff
});
app.controller('controllerTwo', function(User) {
// do stuff
});
app.controller('controllerThree', function(User) {
// do stuff
});
and each controller called from ngRoute:
app.config(function($routeProvider) {
$routeProvider
.when("/one",{,
controller: "controllerOne"
})
.when("/two",{
controller: "controllerTwo"
})
.when("/three",{
controller: "controllerThree"
});
});
... in no particular order
Now, there are a lot of posts that reference angular-deferred-bootstrap, but that library has not been updated since 2015. My question: Is angular-deferred-bootstrap still the preferred method to do this, or is there another / better way?