0

Hi I need to resolve chained promise before my controller loads. According to: https://github.com/angular-ui/ui-router/wiki it should be possible. I have something like that:

usersInit: function (Restangular) {
      return $.get(Restangular.configuration.baseUrl+"/users?limit=1").then(function(data){
              var total = data.total;
              return Restangular.all('users').getList({page: 1, limit: total});
      })
}

And almost everything seems to be fine, I get all records via restangular (which is what I'm trying to achive, because my default restangular setting returns 20 records) but the object returned by return Restangular.all('users').getList is not resolved in my controller.

Any suggestions what's wrong? Or maybe any other way to get it working without chaining promises. I cannot use hardcoded high limit because in theory I can have even larger number of records.

1
  • move all to a service or a factory double return not work Commented Sep 29, 2014 at 9:51

1 Answer 1

1

This worked for me:

usersInit: function ($q) {
                  var promise = $q.when($.get(Restangular.configuration.baseUrl+"/users?limit=1"));
                  promise = promise.then(function (result) {
                    promise = Restangular.all('users').getList({page: 1, limit: total});
                    promise = promise.then(function(list) {
                      return list;
                    });
                    return promise;
                  });
                  return promise;
                }
    }

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.