【发布时间】:2014-05-30 14:44:16
【问题描述】:
我之前已经阅读了一些关于 Angular Promise 的论坛帖子,但无法让它在我的实例中发挥作用。我在后端使用 nodejs /locomotive,前端使用 Angular。
我在控制器中有以下代码,基本上我想使用 slides.path 的路径,我将如何使用 Promise 来执行此操作?任何帮助将不胜感激。
function ProductCtrl($scope, $http, $q) {
$scope.events = [];
$scope.times = [];
var html = [];
var chapters = [];
var path;
//var paPromise = $q.defer();
$http({
url: '/show',
method: 'GET',
params: { eventid:$scope.$routeParams.eventid}
}).success(function(response, code) {
$scope.events = response;
angular.forEach($scope.events.slides, function(slide) {
$http({
url: '/upload',
method: 'GET',
params: {uploadid: slide.upload.toString()}
}).success(function(response, code) {
return "http://www.example.com/"+response.path;
},path);
slide.path = path;
chapters.push(slide);
});
});
}
【问题讨论】:
-
你是带着承诺去做的。 $http 返回一个promise,并且只有在promise 被解决时才调用success 调用。你到底有什么问题?
-
除非您想使用完整的 FRP 或启用旧版自动展开模式。我不确定你想要完成什么。
标签: javascript jquery node.js angularjs promise