在AngularJs控制器中,我需要确保在执行其他任务之前初始化一个极值变量。
var firstPromise = $scope.watch("myParamount"...); // from ng-init
var otherPromises = []; // once obtained myParamount, do others
// something like this?!
$q.firstPromise.then.all(otherPromises).then(function(){
console.log("first, then otherPromises completed!");
})
如何解决这个“假”的代码?
这与问题无关,但是'$ scope.watch'是什么?你可能是指'$ scope。$ watch'?在这种情况下,它不会返回一个承诺,而是一个取消注册的听众。 –
@NikolajDamLarsen所以,这是你downvoted OP的原因?我不知道 – Serge
我没有downvote所以我不知道。 –