angular中因异步问题产生的错误解决方法

方法一
private userTaskList(){
  let auth = this.make_basic_auth("kermit","kermit");
  this.httpc.get("http://localhost:8080/activiti-rest-test/service/runtime/tasks?assignee="+this.user,{//列出当前用户的任务
  headers:{'Authorization' : auth}
}).mergeMap(val=>{
  let tasks:Array<any> = val['data'];
  let task:any = tasks[tasks.length-1];
  let tid:string=task.id;
  return this.httpc.post("http://localhost:8080/activiti-rest-test/service/runtime/tasks/"+tid,{ //提交审批的同时 让申请人完成任务
  "action" : "complete",
"variables": [
    {
      "name":"detoxCenterApproval",
      "value":this.detoxCenterApproval
    }
  ]
},{
    headers:{'Authorization' : auth}
  });}).subscribe(val => console.log(val),
  error =>{ },
  () => {}
  );
}
 
 
 
 
方法二 用promise
  
  let prOrg=this.orgTreeData.reloadPageIfNeed();
  let prPerson=this.personTreeData.reloadPageIfNeed();
  Promise.all([prOrg,prPerson]).then(s=>{ //数据加载完成后再调用方法
  this.orderOrgTreeData = this._convertRows2Subtree();});
 
 
 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/Samuel-Leung/p/9333796.html