-
Notifications
You must be signed in to change notification settings - Fork 3k
resolve and $http requests #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I guess you need to |
Thanks for the help @mostr. I just realized that Here is the solution that worked for me: $stateProvider.
state('test', {
url: '/test',
templateUrl: 'partials/test.html',
resolve: {
items: ['$http', function($http) {
return $http({
method: 'GET',
url: 'models/items.json'
});
}]
},
controller: ['$scope', '$state', 'items', function($scope, $state, items) {
$scope.title = 'My test page';
$scope.items = items.data; // don't forget to add it here!
}]
}); |
Thanks for posting that solution. The documentation for |
Please let me know how the resolve docs could be improved. I'm completely open to editing them. https://github.com/angular-ui/ui-router/wiki#resolve |
Way more examples would be great--all it shows now is how to use the name of a service, but that service seems to do no work. If the documentation says these properties can be either strings or functions, nobody I know would ever guess that you could also feed them an array and expect it to work. I realize that this is an idiom that Angular has chosen to enforce in many other locations with their attempt to bring named argument support to a language which doesn't want them, but it never looks right no matter how many times you see it elsewhere. |
Ok, @oncomeme could you do me a favor and look at the revised Resolve docs? https://github.com/angular-ui/ui-router/wiki#resolve I want to know if they make more sense and give a more complete picture. |
A couple things I'd still like to see:
|
Good ideas. I'll add them this weekend. |
I figured out at least part of the problem was that I need to return |
ok I added examples for your suggestions as well. Hopefully that makes it a bit easier for newcomers. |
Thanks. That's very helpful. |
I'm noticing a bizarre chicken-and-egg situation when trying to use the Are these |
I'm pretty certain this issue has been discussed before. Try searching closed issues. |
The closest thing I found is still open, and I think this is a fairly significant gotcha that should either be fixed or documented: |
Actually I think this is actively being fixed by @ksperling |
Follow up question... I have this code in the config section:
... and have the following AppFactory
But when I execute, the console.log message in the success callback never gets executed. The browser log shows the http call executes OK with code 200. I am assuming this means angular thinks it has failed or should I be doing something else? I even tried returning the $q promise object (as suggested in stack overflow) but no success. In the factory code if I use test data (i.e., no HTTP call) everything works fine even if I don't return a promise object. Any pointer on where the problem could be? Appreciate any pointers to help me debug... |
How is the resolve supposed to work for asynchronously resolve data when it has no true callback method?
This is what I'm trying to do, but the
$timeout
method is not behaving like a callback method and hence the$scope.items
is never present when the partial is rendered.In the examples
resolve
is mentioned along with asynchrony data, but I can not get it to work.The text was updated successfully, but these errors were encountered: