从 post api call 得到响应后,抛出错误 => .pipe is not a function
After getting the response from post api call , an error is thrown => .pipe is not a function
我正在进行 api 调用,并期待它的响应可以传递给第二次 api 调用,但我收到一个错误
ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function
线上 .pipe(switchMap((resarray:any)=>{
TS代码
someFunction(floor){
floor.entities.forEach(element => {
let desiredTempForZone;
this.getCurrentValue(element.name).subscribe((des) =>
{
currentTempForZone = des
});
console.log(currentTempForZone);
})
}
getCurrentValue(eleName){
let roomObj = this.getRoomObj(eleName);
let equipRef = roomObj.map(equip => equip.entities.filter(entity => entity.entities.length > 0)[0])[0];
return this.helperService.getPointIdbyTags(this.buildings, ['current',
'temp'], equipRef.referenceIDs.room)[0]
.pipe(switchMap((resarray:any)=>{
const res = resarray[0]
return this.siteService.getHisPointData(res, 'current')
.pipe(
map(this.helperService.stripHaystackTypeMapping),
)
}));
}
然后我想把它传递给
switchMap((resarray:any)=>{
const res = resarray[0]
return this.siteService.getHisPointData(res, 'current')
看起来 getPointIdbyTags(buildingObj: any, zoneTags: any, roomRef: string = undefined) { ... }
是一个简单的函数,returns 是一个数组。所以不需要使用 .pipe()
和 .switchMap
运算符,因为使用 RXJS 可以更容易地 编写异步或基于回调的代码.
您的代码应如下所示:
getCurrentValue(eleName){
let roomObj = this.getRoomObj(eleName);
let equipRef = roomObj.map(equip => equip.entities
.filter(entity => entity.entities.length > 0)[0])[0];
let res = this.helperService.getPointIdbyTags(this.buildings, ['current',
'temp'], equipRef.referenceIDs.room)[0];
// If this method `getHisPointData()` really makes HTTP call
// and if it returns observable than you can use `pipe` operator
return this.siteService.getHisPointData(res, 'current')
.pipe(
map(this.helperService.stripHaystackTypeMapping),
)
.subscribe(s => console.log(s));
}
我正在进行 api 调用,并期待它的响应可以传递给第二次 api 调用,但我收到一个错误
ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function
线上 .pipe(switchMap((resarray:any)=>{
TS代码
someFunction(floor){
floor.entities.forEach(element => {
let desiredTempForZone;
this.getCurrentValue(element.name).subscribe((des) =>
{
currentTempForZone = des
});
console.log(currentTempForZone);
})
}
getCurrentValue(eleName){
let roomObj = this.getRoomObj(eleName);
let equipRef = roomObj.map(equip => equip.entities.filter(entity => entity.entities.length > 0)[0])[0];
return this.helperService.getPointIdbyTags(this.buildings, ['current',
'temp'], equipRef.referenceIDs.room)[0]
.pipe(switchMap((resarray:any)=>{
const res = resarray[0]
return this.siteService.getHisPointData(res, 'current')
.pipe(
map(this.helperService.stripHaystackTypeMapping),
)
}));
}
然后我想把它传递给
switchMap((resarray:any)=>{
const res = resarray[0]
return this.siteService.getHisPointData(res, 'current')
看起来 getPointIdbyTags(buildingObj: any, zoneTags: any, roomRef: string = undefined) { ... }
是一个简单的函数,returns 是一个数组。所以不需要使用 .pipe()
和 .switchMap
运算符,因为使用 RXJS 可以更容易地 编写异步或基于回调的代码.
您的代码应如下所示:
getCurrentValue(eleName){
let roomObj = this.getRoomObj(eleName);
let equipRef = roomObj.map(equip => equip.entities
.filter(entity => entity.entities.length > 0)[0])[0];
let res = this.helperService.getPointIdbyTags(this.buildings, ['current',
'temp'], equipRef.referenceIDs.room)[0];
// If this method `getHisPointData()` really makes HTTP call
// and if it returns observable than you can use `pipe` operator
return this.siteService.getHisPointData(res, 'current')
.pipe(
map(this.helperService.stripHaystackTypeMapping),
)
.subscribe(s => console.log(s));
}