Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

angular - After getting the response from post api call , an error is thrown => .pipe is not a function

I am making an api call and expecting a response from it which can be passed to 2nd api call but I am getting an error

ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function

on line .pipe(switchMap((resarray:any)=>{

TS code

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),
                       )
              }));
}

And then I am trying to pass it on to

switchMap((resarray:any)=>{
               const res = resarray[0]
               return  this.siteService.getHisPointData(res, 'current')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It looks like that getPointIdbyTags(buildingObj: any, zoneTags: any, roomRef: string = undefined) { ... } is a simple function which returns an array. So there is no need to use .pipe() and .switchMap operators because RXJS is used to make it easier to compose asynchronous or callback-based code.

Your code should look like this:

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));

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...