Angularjs 在角度资源中添加配置

Angularjs 在角度资源中添加配置,angularjs,angular-resource,angular-http-auth,Angularjs,Angular Resource,Angular Http Auth,我使用的是身份验证。在http auth拦截器中,我使用以下方式登录: var data = 'username=' + encodeURIComponent(user.userId) + '&password=' + encodeURIComponent(user.password); $http.post('api/authenticate', data, { headers: { 'Conten

我使用的是身份验证。在http auth拦截器中,我使用以下方式登录:

        var data = 'username=' + encodeURIComponent(user.userId) + '&password=' + encodeURIComponent(user.password);
        $http.post('api/authenticate', data, {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            ignoreAuthModule: 'ignoreAuthModule'
        })
ignoreAuthModule
用于告诉
ignoreAuthModule
此登录方法将被auth侦听器忽略

现在,我有一些$resource的请求,比如:

.factory('SomeDataService', function ($resource) {
    return $resource('api/some/data', {}, {
       'get': { method: 'GET'}
    });
})
身份验证拦截器也会忽略我想要的
SomeDataService.get()
,因为我需要自己控制401错误

所以,我的问题是,对于ngResource,有没有办法在$http中设置这样的配置

[根据评论更新] 我已收听了
需要登录的事件

    $rootScope.$on('event:auth-loginRequired', function (rejection) {
        $log.log(rejection);
        // I need to get the request url and for some specific url, need to do something.
        $rootScope.loginPopup();
    });

但是'rejection'参数没有我需要的请求的上下文数据。我需要获取请求url并检查,对于某些指定的url,我需要做一些事情。

ngResource模块构建在$http之上。因此,不可能在$resource中配置使用$http可以完成的所有工作。我想下面的链接将引导您在检查ngResource文档后对

,我得到的解决方案如下:

.factory('SomeDataService', function ($resource) {
    return $resource('api/some/data', {}, {
       'get': { method: 'GET', ignoreAuthModule: 'ignoreAuthModule'}
    });
})
只需如上所述添加配置项。这将相当于广告:

$http.post('api/some/data', data, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        ignoreAuthModule: 'ignoreAuthModule'
    })
您正在收听“event:auth login required”,对吗?为什么不检查一下它的来源,然后采取相应的行动呢?