I am new to AngularJS and have a service that loads my initial user configuration
angular.module('myApp').service('myService', ['$http', function ($http) { var self = this; self.user = {}; self.loadConfiguration = function () { $http.get('/UserConfig').then(function (result) { self.user = result.data; }); }; self.loadConfiguration(); }]);
I have a controller that uses the configuration from this service
angular.module('myApp').controller('myController', ['$scope', 'myService', function ($scope, myService) { var self = this;
The problem is that myService.user.something may be undefined, because the AJAX request may not complete when this code is called. Is there any way to end the service before running any other code? I want the loadConfiguration service function to be run only once, regardless of the number of controllers that depend on it.
angularjs angularjs-service
user1625066
source share