Angular 如何在其他数组填充数据之前停止执行数据检索

Angular 如何在其他数组填充数据之前停止执行数据检索,angular,Angular,伙计们,我有一个关于angular的数据表,我想用一个对象填充它,但首先我需要修改它的数据值。问题是新数据来自另一个服务,因此在检索和修改Datatable数据之前,首先需要检索department服务数据。也许回调函数可以解决我的问题,但我不知道如何在angular上使用它 我的代码: ngOnInit() { this.id=this._Activatedroute.snapshot.paramMap.get("id"); this.service.get_cars().

伙计们,我有一个关于angular的数据表,我想用一个对象填充它,但首先我需要修改它的数据值。问题是新数据来自另一个服务,因此在检索和修改Datatable数据之前,首先需要检索department服务数据。也许回调函数可以解决我的问题,但我不知道如何在angular上使用它

我的代码:

  ngOnInit() {
    this.id=this._Activatedroute.snapshot.paramMap.get("id");
    this.service.get_cars().subscribe((data)=>{// get departement service data
      console.log(data);
      this.UIGestionlist = json2array(data);
      this.departements = this.UIGestionlist[5];
      this.ChauffeursListe = this.UIGestionlist[6];

    });
    this.service.Car_log_charge(this.id).subscribe(data=>{
      console.log(data);
      this.Car_logs = json2array(data);
            for(let i= 0; i<this.Car_logs.length;i++){// modify Datatable departement value
        console.log(this.Car_logs[i].Department);
        for(let m =0 ; m<this.departements.length;m++){
          if(this.departements[m].Id == this.Car_logs[i].Department){
            console.log('Congs '+ this.departements[m].Id);
            this.Car_logs[i].Department = this.departements[m].Name;
          }
        }
      }

      this.listdata = new MatTableDataSource(this.Car_logs);
      this.listdata.sort = this.sort;
      this.listdata.paginator = this.paginator;
    });
  }
}
ngOnInit(){
this.id=this.\u Activatedroute.snapshot.paramMap.get(“id”);
this.service.get_cars().subscribe((数据)=>{//get部门服务数据
控制台日志(数据);
this.UIGestionlist=json2array(数据);
this.departments=this.UIGestionlist[5];
this.chauffersliste=this.UIGestionlist[6];
});
this.service.Car\u log\u费用(this.id).subscribe(数据=>{
控制台日志(数据);
this.Car_logs=json2array(数据);
对于(让i=0;i签出
switchMap
。这允许您“链接”观察对象。您可以进行第一次呼叫(
get\u cars
),执行数据操作,然后订阅第二次呼叫(
Car\u log\u change