AngularJS how do I execute code only after a promise is resolved? (with Restangular) -


this might nooby question still haven't been able head around promises , how write code them. (i've read several articles of them abstract , haven't written enough have clear picture) i've got angujlarjs application gets data through http request server sends promise @ first. i've been able retrieve response promise , use in app. because code poorly written. executes other code before promise resolved leading problems. starts loading page before has data.

what have is:

var usertotals = *http request returns promise  $scope.data = usertotals.$object  //code someting $scope.data 

what need (i think)

var usertotals = *http request returns promise  $scope.data = usertotals.$object.   beforethisresolves(function{       show fancy loading icon or })   .whenthis resolves(function{     //code someting $scope.data   } 

however can't syntax correct.

this looks in general:

var promise = $http.post('/url');  console.log('request started');  promise.then(function(result) {   console.log('success');   console.log(result); }, function() {   console.log('failure'); }); 

in fact, $q angularjs documentation helped me deal head around promises concept.

hope helps!


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -