Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to resolve a promise before any sub-resolves in AngularUI Router

I have 2 states in coffeescript...

stateProvider.state  'test',
    ...
    resolve:
        user: (LongRunning)->
            LongRunning.authenticate().then ->
                console.log("We are authenticated!")

stateProvider.state  'test.child',
    ...
    resolve:
        other: (AfterAuth)->
            AfterAuth.soSomethingWithAuth().then ->
                console.log("We are done!")

Of course this doesn't work because the child resolve is kicked off before the parent's auth method has been resolved. This means the second function won't be authenticated and cause the entire state to fail.

Now it doesn't need to necessarily be part of the State path but it needs to be fully completed by the time the resolve functions are called.

How would I make sure the function from parent is fully resolved before calling the method in child?

Bad (?) Solution

The one answer I have been able to come up with is to use the manual bootstrap process. However, this is tedious since I would need to rewire all my services. Is there anyway I can do it inside Angular?

like image 496
Jackie Avatar asked Jun 21 '17 21:06

Jackie


1 Answers

Do you use AngularUI Router for Angular 2 or AngularJS? I think that is AngularJS on the fact that you use coffeescript and AngularUI Router. This is Angular tag not AngularJS.

Anyway in AngularUI Router one resolver can depends on another one. Something like that:

 function firstStep($stateParams, resolveStatus) {
   return $q.resolve();
 }

 resolve: {
   firstStep: firstStep,
   secondStep: ['firstStep', function (firstStep) {
   ...
   }]
 }
like image 152
Julia Passynkova Avatar answered Oct 18 '22 17:10

Julia Passynkova