I got this resolve in my state
first I get the test
into a variable, and then I want to get the test2
variable, but in order to get test2
I have to wait for test
again.
Is there a cleverer way of doing this?
Thank you
resolve: {
one: function (test) {
return test.gettest().$promise.then(data => {
return data;
});
},
two: function (test, test2, $stateParams) {
return test.gettest().$promise.then(test=> {
return test2.gettest2(test.id, $stateParams.id).$promise.then(data => {
return data;
});
});
}
},
If you inject the first resolve variable (one
) into the second resolve statement, angular ui router is smart enough to realize that it will not run the second resolve statement until the first one has completed. So what you would do looks something like below:
resolve: {
one: function (test) {
return test.gettest().$promise.then(data => {
return data;
});
},
two: function (one, test2, $stateParams) {
//one is equal to the result of test.gettest()
return test2.gettest2(one.id, $stateParams.id).$promise.then(data => {
return data;
});
});
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With