Angularjs $q与私有$$状态?

Angularjs $q与私有$$状态?,angularjs,angular-promise,Angularjs,Angular Promise,使用Angular的$q时,为什么所有内容都保存在$$state对象下?我的印象是,双美元在角度上意味着私人的,在这种情况下,这对我来说不太有意义。我是否错误地履行了我的承诺 仅在测试中,这将返回具有$$状态的对象: $scope.makePromise = function(){ return $q(function(resolve, reject){ resolve('Promise Resolved'); }); } 嗯,$$state就是Angular如何跟踪其承诺的内

使用Angular的$q时,为什么所有内容都保存在$$state对象下?我的印象是,双美元在角度上意味着私人的,在这种情况下,这对我来说不太有意义。我是否错误地履行了我的承诺

仅在测试中,这将返回具有$$状态的对象:

$scope.makePromise = function(){
  return $q(function(resolve, reject){
    resolve('Promise Resolved');
  });
}

嗯,
$$state
就是Angular如何跟踪其承诺的内部状态。您不应该在自己的代码中使用它,将来它可能会崩溃

相反,如果要检查承诺的状态,则应向其添加
,然后添加
处理程序:

myPromise.then(function(el){
    // I got here after the promise resolved and `el` is the value
    // it fulfilled with.
}, function(e){
    // I got here after the promise rejected and `e` is the error
    // it rejected with.
});

嗯,
$$state
就是Angular如何跟踪其承诺的内部状态。您不应该在自己的代码中使用它,将来它可能会崩溃

相反,如果要检查承诺的状态,则应向其添加
,然后添加
处理程序:

myPromise.then(function(el){
    // I got here after the promise resolved and `el` is the value
    // it fulfilled with.
}, function(e){
    // I got here after the promise rejected and `e` is the error
    // it rejected with.
});

你的承诺是正确的。正如doc所说:它是ES6 promise的构造函数。您还希望它返回什么?您的承诺是正确的。正如doc所说:它是ES6 promise的构造函数。您还希望它返回什么?