3

I'm trying to defer loading of my main controller/template (AppController) until I load the users profile from a service.

For all navigation routes, I'm using $routeProvider with resolve

.when('/edit/:editId', {
    templateUrl: 'editTemplate.html',
    controller: 'EditController' // this is a child controller of AppController
    resolve: {
         currentUser: ['svc.user', function(userSvc) { return userService.getUser(); }]
    }
// and so on..

But for AppController I'm using

How can I do a resolve for AppController? Essentially, I'd like a userService.getUser() which returns a promise to finish executing before AppController is actually run, I'm not sure how to do this using ng-init though (or if it's possible, i thought only expressions not promises could be executed).

Thanks for any help/assistance.

4
  • 2
    See this video egghead.io/video/angularjs-resolve and good demo for your exact issue here: github.com/johnlindquist/angular-resolve Commented Mar 26, 2013 at 10:53
  • Thanks charlietfl - so the hidden 'app' promise is what I'll need. Thanks! Commented Mar 26, 2013 at 11:42
  • no...should resolve the promise from the service. Look how is done in demo: github.com/johnlindquist/angular-resolve/blob/master/client/js/… Commented Mar 26, 2013 at 11:59
  • yes, but you can also put a module in there too I found. So in their case they pass the reference to app. In my code, I'm using minified code with requirejs, so i'm using string literals. So I have a 'app.core' module. I use 'app.core' : { // resolve stuff } which ensures that when it gets the core, it also caches the user.... unless i've got it totally wrong ?!? hope not Commented Mar 26, 2013 at 13:42

1 Answer 1

1

As seen in this video: http://egghead.io/video/angularjs-resolve/

You should try:

.when('/edit/:editId', {
  templateUrl: 'editTemplate.html',
  controller: 'EditController' // this is a child controller of AppController
  resolve: {
     currentUser: ['svc.user', function(userSvc) { return userService.getUser(); }]
     app: function ($q) {
                var defer = $q.defer();
                defer.resolve();
                return defer.promise;
     }
}
Sign up to request clarification or add additional context in comments.

1 Comment

should be resloving the promise of userService not creating an arbirary one

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.