Krihox Krihox - 5 months ago 17
AngularJS Question

Can't get a value from $http promise and then() code not executed

I already had a problem with

service in the past which I resolved by creating a service to handle my requests (for those who are interested, here's the link of the answer which helped me, the EDIT part : creating a service for $http request ).

The problem now is that this solution seems inefficient to handle bigger
requests. In the previous one, I only assigned a word that were returned by the request to a
value. Now, what is returned is a whole configuration in JSON format (that I also want to store in the

I understand the concept of promises, the fact that the value returned by
is a null string until the response comes, and that it could take time. But here, the configuration is not that long, and I never seem to get an answer ; I display the variable that recieves the value on the view and it doesn't change when the function is called.

Here's the code :


<button ng-click="loadconfig()">load</button>


app.controller('ConfigurationCtrl', function ($scope, $rootScope, configloader) {
$scope.loadedConfig = 'noconfig'
$scope.loadconfig = function() {
configloader.load().then(function (response) {
$scope.loadedConfig =;


.factory('configloader', configloaderFactory);

function configloaderFactory($http) {

var service = {
load: load

return service;

function load() {
return $http.get('url/config');

If I call a 'lesser weighted request', this works without a problem. I also tried other methods to make this call but in every case it didn't work... (with
, with success()/error(), or with a custom

Is the code in the
supposed to execute when I get the response ? (I assume it is, but it never does).



Try return the promise in you factory, somthing like :

function load() {
     var promise =   $http.get('url/config').then(function(response){
     }, function(err){
       return err;
     return promise;