如何访问promise对象的值?

时间:2015-07-19 22:03:21

标签: javascript angularjs angular-promise

嗨我有一个对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,这会导致提交操作生效点击两下后!

对此有任何帮助将不胜感激!

0 个答案:

没有答案