angular4 前端(伪)同步请求、阻塞请求后台

1,(伪)同步请求获取后台数据,按先后顺序执行请求,示例:

import { map, mergeMap } from "rxjs/operators";

this.http.get("api/sysCityRegion/address", { parentId: "CN" }).pipe(mergeMap((res: any) => {
          this.province = res;
          this.region = [];
          this.city = [];
          this.provinceCode = "150000";
          this.regionCode = null;
          this.cityCode = null;
          return this.http.get("api/sysCityRegion/address", { parentId: "150000" }) //默认设置市
        })).pipe(mergeMap((res1: any) => {
          this.city = res1;
          this.region = [];
          this.regionCode = null;
          this.cityCode = "150500";
          return this.http.get("api/sysCityRegion/address", { parentId: "150500" })//默认设置区
        })).subscribe((res2: any) => {
          this.region = res2;
          this.regionCode = null;
        })
 

2,当满足一定条件时,才加载simple-table的数据,解决方法:

[columns]="columns_card" toTopInChange showSizeChanger showQuickJumper showTotal>

{{item.disable?'-':index+1+(st_card.pi-1)*st_card.ps}}

===》 最开始不初始化url_card,待异步请求后台返回满足条件后,再对url_card进行赋值即可

 

你可能感兴趣的:(Angular)