【发布时间】:2020-03-13 18:47:54
【问题描述】:
我有一个 API,它需要标头中的国家代码以及授权令牌和承载。 我能够在我的组件文件中获取 mat-select 值。 但是,我的 api 标头和令牌正在服务文件中设置。 谁能帮我弄清楚如何将 mat-select 的值从组件传递到服务文件?
现在我将国家值硬编码为“au”,但我希望它根据 mat-select 下拉值进行设置。
在组件文件中获取 mat-select 值的代码:
onCountrySelection() {
console.log(this.countryValue);
sessionStorage.setItem('countryCode', this.countryValue);
}
服务类文件中的API;
uploadConfig(templateName, JsonBody) {
const header = new HttpHeaders().set(
'Authorization',
'Bearer ' + sessionStorage.getItem('token'),
).set(
'country',
'au'
);
return this.httpClient.post(
this.localUrl + '/pattern/' + templateName + '/flow', JsonBody,
{ headers: header }
);
}
【问题讨论】:
标签: javascript angular typescript angular8