更改角度控制器内的http标头

时间:2016-05-06 08:34:43

标签: javascript angularjs

您好我需要从控制器内部更改http标头。它使用$ httpProvider在config中工作,但这不是我想要的。

我尝试了这个,但它说的是未定义的推送。

$http.interceptors.push([function() {
    return {
        'request': function(config) {
            config.headers = config.headers || {};
            //add nonce to avoid CSRF issues
            config.headers['X-WP-Nonce'] = myLocalized.nonce;

            return config;
        }
    };
}]);

1 个答案:

答案 0 :(得分:4)

在$ http的配置对象中,您有一个字段标题,它是字符串或函数的映射。

你可以这样使用它:

env.authenticatorService.embed(v, result)