小编Nat*_*nze的帖子

AngularJS - 等待多个资源查询完成

我有一个用ngResource定义的工厂:

App.factory('Account', function($resource) {
    return $resource('url', {}, {
        query: { method: 'GET' }
    });
});
Run Code Online (Sandbox Code Playgroud)

我正在多次调用此工厂上定义的查询方法.调用可以异步发生,但我需要等待两个调用完成才能继续:

App.controller('AccountsCtrl', function ($scope, Account) {
    $scope.loadAccounts = function () {
        var billingAccounts = Account.query({ type: 'billing' });
        var shippingAccounts = Account.query({ type: 'shipping' });

        // wait for both calls to complete before returning
    };
});
Run Code Online (Sandbox Code Playgroud)

是否有办法使用ngResource定义的AngularJS工厂,类似于jQuery的$ .when().then()功能?我宁愿不将jQuery添加到我当前的项目中.

angularjs

104
推荐指数
3
解决办法
7万
查看次数

标签 统计

angularjs ×1