gpt4 book ai didi

javascript - 如何将两个 Angular 应用程序的信息作为第二个应用程序路径的标题传递?

转载 作者:行者123 更新时间:2023-11-28 06:17:36 26 4
gpt4 key购买 nike

我有两个 Angular 应用程序。在第一个应用程序中,我有一个按钮,单击该按钮时我想加载第二个应用程序(即位于 webportal 文件夹上的第二个应用程序的 index.html 文件),当然还要更改 url 。我可以像这样简单地做

<a href="http://localhost:8000/webportal/">Second App</a>

但问题是我想在此调用的 header 中添加一些属性,并在第二个应用程序的index.html中读取它们,添加 header ,我尝试在第一个应用程序中使用请求拦截器并进行ajax调用,然后在此调用成功,使用 window.open 更改 url,如下所示

`$scope.buttonClicked= function() {
$http({method: 'GET', url: 'http://localhost:8000/webportal/'}).then(function(data) {
window.open(data.config.url,'_self' );
});
};

`

由于 window.open 窗口重新加载后,我看不到使用第一个应用程序的请求拦截器添加的 header 。我应该如何在 "http://localhost:8000/webportal/" 的调用中添加 header 并在第二个应用程序的 index.html 中读取该 header 。

请帮助我。

最佳答案

您可以通过这种方式传递 header

    var config = {
//other than headers you can pass info from here
headers: {
'Authorization': 'Token ' + 'your token'
'Accept': 'application/json;'
//If you have any headers you can specify here
}
};
$http.get('http://localhost:8000/webportal/',config)
.success(function(data){
window.open(data.config.url,'_self' );
});

关于javascript - 如何将两个 Angular 应用程序的信息作为第二个应用程序路径的标题传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35825465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com