how to use switchMap to cancel pending http requests and taking the last subscribe only?

后端 未结 3 1550
礼貌的吻别
礼貌的吻别 2021-01-19 05:11

i tried canceling pending http request using subscription.unsubsribe like this:

getAgentList(pageNumber: number, filter: string): any {
   let requestUrl: s         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-19 05:18

    tried and it even did not got out to the server

    getAgentList(pageNumber: number, filter: string): any {
        let requestUrl: string = 'api/service/agents_search?ACCT=' 
      +this.accountId;
        if (filter) {
            requestUrl = requestUrl + '&filter=' + filter;
        }
        if (pageNumber) {
            requestUrl = requestUrl + '&pageNumber=' + pageNumber;
        }
        this.$filter.next(requestUrl)
    
        this.$filter.switchMap(requestUrl => 
        this.backEndCommService.getData(requestUrl))
                .subscribe(
                    (res: any) => {
                        let serverResponse: ServerResponse = new 
                        ServerResponse(this.accountId, pageNumber, 
                        res.search_results, 
                        res.resultRows, res.pageSize, res.resultPages)
                        this._agentListData$.next(serverResponse);
                    },
                   (err: HttpErrorResponse) => {
    
                console.log('handling error');
          });
    }
    

    this line switchMap(requestUrl => this.backEndCommService.getData(requestUrl)) did not made the call and fall silently.....mmmm

提交回复
热议问题