嗨我有一个对firebase的异步调用,它返回一个promise,我想将promise的值赋给一个范围变量,但是我无法做到。
$scope.submitQuestion = function(){
$scope.post.createdTime = createdtime;
$scope.post.creator = $scope.user.profile.username;
$scope.post.creatorUID = $scope.user.uid;
$scope.post.creatorpic = $scope.user.profile.userpic;
$scope.post.postmedia = $scope.object.video.info.uuid;
$scope.post.postcountupdate = PostCount.getpostcount().$loaded().then(function(data){
var postunivcount = 0;
postunivcount = data.$value;
var postnewcount = postunivcount + 1 ;
console.log('new count')
$scope.postidcount = postnewcount;
PostCount.updatepostcount(postnewcount);
return postnewcount;
});
这给了我$$state > value : 25
的承诺
我想将值25
分配给$scope.post.postcountupdate
你能告诉我怎么做到这一点吗?
我尝试使用$scope.postidcount = postnewcount;
将值分配给Scope,并将范围值分配给post对象,但在undefined
结算之前我会$loaded
,这会导致提交操作生效点击两下后!
对此有任何帮助将不胜感激!