You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

面试技术问询:$q.all方法的正确使用语法有哪些?

Valid Syntax for AngularJS's $q.all() Method

Let's break down each option to figure out which are valid uses of $q.all():

  • First option (array of promises):

    $q.all([promise1(), promise2()]).then((values) => { … });
    

    This is valid. $q.all() accepts an array of promise instances (or calls to promise-returning functions, since invoking them returns a promise). The .then() callback will receive an array of resolved values, ordered to match the input promises.

  • Second option (individual arguments):

    $q.all("promise1", "promise2").then((values) => { … });
    

    This is invalid. $q.all() doesn't accept multiple standalone arguments—it expects either a single array or a single object as its only parameter. On top of that, passing string literals here is meaningless, since they aren't promises.

  • Third option (object of promises):

    $q.all({"promise1": promise1(), "promise2": promise2()}).then((values) => { ... });
    

    This is valid. $q.all() also supports an object where each property maps to a promise (or a call to a promise-returning function). The .then() callback will receive an object with the same keys, each mapped to their corresponding resolved value.

To sum up: the first and third options are the correct syntax for $q.all().

内容的提问来源于stack exchange,提问作者Rorbert Gilbert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:47:03