【发布时间】:2021-07-02 20:49:00
【问题描述】:
在我的 Angular-12 应用程序中,我在服务中有以下代码:
constructor(private http: HttpClient, private router: Router) {
var currentUser = JSON.parse(localStorage.getItem('user')|| '{}');
this.token = currentUser && currentUser.token;
}
public getAllCountries(): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
"Content-Type": 'application/json',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, Authorization, Content-Type, Accept",
"Authorization" : "Bearer " + this.token
})
};
return this.http.get(this.apiUrl + '/fetchCountries', httpOptions )
.pipe(
map((response: Response) => {
return response;
})
);
}
这一行被高亮显示:
map((response: Response) => {
返回响应;
然后我得到了这个错误:
Argument of type 'OperatorFunction<Response, Response>' is not assignable to parameter of type 'OperatorFunction<Object, Response>'.
The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
Type 'Object' is missing the following properties from type 'Response': headers, ok, redirected, status, and 12 more.ts(2345)
如何解决?
谢谢
【问题讨论】:
标签: angular