Skip to content Skip to sidebar Skip to footer

Angular Ui-router Cannot Resolve $resource Results

In one of my UI-router states, I have the following link '/users', which points to a page that shows a list of users. Below is the code I wrote to resolve the list of users by usin

Solution 1:

Change it to:

users: function ($resource) {
    return$resource('http://localhost:8080/api/users').query().$promise;
}

Because that way you're returning the promise, and by using then(...), you're resolving the promise within and just returning data thus it won't pass it to the controller because it's returning them after the controller has loaded.

Solution 2:

Using $q service will help you

var userVal = $resource('http://localhost:8080/api/users').query()
retrun $q.resolve(userVal.$promise).then(function(r){ return r;});

Inside you controller, you are good to go

vm.users = users

Post a Comment for "Angular Ui-router Cannot Resolve $resource Results"