要解决Angular 7的HttpHeaders为空的问题,可以尝试以下解决方法:
import { HttpHeaders } from '@angular/common/http';
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
});
const options = { headers: headers };
this.http.post(url, data, options).subscribe(
(response) => {
// 处理响应
},
(error) => {
// 处理错误
}
);
const headers = new HttpHeaders();
headers.set('Content-Type', 'application/json');
headers.set('Authorization', 'Bearer ' + token);
const options = { headers: headers };
this.http.post(url, data, options).subscribe(
(response) => {
// 处理响应
},
(error) => {
// 处理错误
}
);
这些是解决Angular 7的HttpHeaders为空问题的一些常见方法。根据具体情况,可能需要根据实际需求进行适当的调整和修改。