我在解决我的承诺时遇到了问题——奇怪的是,我的标记中出现了这个问题:
{{details.customer_email}}
它正确解析,并显示“$http”请求返回的电子邮件地址。
但是,尝试访问此:
$scope.user = {
...
emailAddress : $scope.details.customer_email,
...
};
是null
。
这是相关的块:
$scope.session = {
is_authenticated: false,
customer_email: null
};
var detailsDeferred = $q.defer();
$scope.details = detailsDeferred.promise;
$scope.authed = function () {
$http({
url: 'http://api.foo/auth',
withCredentials: true,
method: "GET",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).success(function (data, status, xhr) {
$scope.session = {
is_authenticated: data.is_authenticated,
customer_email: data.customer_email
};
detailsDeferred.resolve($scope.session);
})
...
return $scope.session;
};
$scope.authed();
$scope.user = {
...
emailAddress: $scope.session.customer_email
...
};