Angular2 HTTP using observables subscribe showing data undefined

前端 未结 2 1157
后悔当初
后悔当初 2021-01-05 22:50

I don\'t know what I\'m doing wrong but somehow i\'m not able to read data, though the data is coming from server in response and even the data is getting showed inside serv

相关标签:
2条回答
  • 2021-01-05 23:15

    This is probably because you are trying to access your allocatedAssetsLists before the data is actually returned from the service.

    If you are accessing it in your template you can use a simple ngIf to make sure you only try to display it once the data is available.

    If this is not it, we need more information on your problem to help.

    0 讨论(0)
  • 2021-01-05 23:38
    listByEmpId(empId:string){
    
        this.adminService.getAllocatedAssets(empId).subscribe(
        res => {
          this.allocatedAssetsList = res;
          console.log(this.allocatedAssetsList);
        },
        error =>  this.errorMessage = <any>error);
    }
    
    0 讨论(0)
提交回复
热议问题