gpt4 book ai didi

javascript - 类型错误 : map is not a function

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:50 25 4
gpt4 key购买 nike

我正在尝试对 API 进行 POST 调用,但收到标题中的错误。我已经检查了所有其他相关问题,并确保没有这些问题。我已经导入了 rxjs map 运算符。事实上,我在前端 Angular 6 应用程序的数百个其他 http 调用中使用了完全相同的语法,没有出现任何问题。

这是导致问题的代码片段:

public createMap(map) {
map.companyId = this.company.getCompanyId();
const temp = this.json.clone(map);
temp.settings = this.json.manageJSON(temp.settings, true);

return this.authHttp.post(environment.coreApiPath + 'importMaps', temp)
.pipe(map((res: any) => {
map.ID = res.ID;
map.tempName = null;
this.maps.push(map);
return map;
}),
catchError(error => { throw Error('Custom Error: There was an error when attempting to create this import map.') }));
}

错误在读取 .pipe(map((res: any) => {

知道是什么导致了这个问题吗?

以下是我的导入,以防你想知道:

import { HttpClient } from '@angular/common/http';
import { map, catchError } from 'rxjs/operators';

最佳答案

您的参数 map 正在隐藏您导入的 map:

import { map, catchError } from 'rxjs/operators';
// ^^^------------------- import

// ...

public createMap(map) {
// ^^^----------- parameter

所以在createMap中,不能使用导入的map;这是不可访问的。

考虑重命名参数或重命名导入。

关于javascript - 类型错误 : map is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52974132/

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