Answer the question
In order to leave comments, you need to log in
AngularJS. How to implement waiting for the completion of promis-s?
Hello! What is the actual problem: I have a User.hasRole(string) method, there is a request to the server to get data about the user
var self = this;
this.userData = null;
$q.all(Auth.currentUser()) /* Внутри происходит запрос */
.then(function(currentUser) {
self.userData = currentUser;
self.isAuth = true;
},function(error) {
self.userData = null;
self.isAuth = false;
});
<li ng-if="hasRole('user')">
...
</li>
Answer the question
In order to leave comments, you need to log in
Lay out the full service code and an example of using hasRole.
For app-wide data that is supposed to be preloaded at application startup, I would use the angular deferred bootstrap module.
I may not understand the essence of the problem correctly, but it seems to me that you want the view to be displayed only after loading the data. In this case, you can apply controller resolvers (if you use ngRoute/uiRouter).
It is also not clear why you use $q.all when there is one promise for everything. Well, they say $q.all expects an array and will pass an array to the arguments
Auth.currentUser().then(function(currentUser) {
self.currentUser = currentUser;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question