这可能是一个没有意义的问题,但我仍然无法把握自己的承诺,特别是如何编写代码。 (我已阅读过几篇文章,但其中大部分都是抽象的,而我只是没有写足够清晰的图片) 我有一个AngujlarJS应用程序,通过http请求获取数据到另一个服务器,第一。我已经能够从promise中检索响应并在我的应用中使用它。但是,因为我的代码写得不好。它在承诺解决导致问题之前执行其他代码。它在有数据之前开始加载页面。AngularJS如何在解决承诺后才执行代码? (with Restangular)
我有什么是:
var userTotals = *http request which returns a promise
$scope.data = userTotals.$object
//code that does someting with $scope.data
我需要的是(我认为)
var userTotals = *http request which returns a promise
$scope.data = userTotals.$object.
beforethisresolves(function{
show fancy loading icon or something })
.whenthis resolves(function{
//code that does someting with $scope.data
}
但我不能得到正确的语法。
http请求退回'promise',你有'then' https://docs.angularjs.org/api/ng/service/$http –