Angular 未从console.log in循环方法中获取任何数据

Angular 未从console.log in循环方法中获取任何数据,angular,Angular,我试图建立一个数据集,我可以使用我的单选按钮选项,但我有困难时,试图建立各自的数据。我调用一个服务端点,它为我提供了3个对象。在每个对象中都有一个名为的值。如果对象将此值设置为Y,则我希望将其添加到可用于单选按钮选项的数据集中。为了更好地解释,我在代码中添加了注释 这是我的密码 getLoanAdjustmentPreValidate() { this.avafService.GetAVAFPreValidateLoanAdjustment(this.getAVAFPreValidateLoan

我试图建立一个数据集,我可以使用我的单选按钮选项,但我有困难时,试图建立各自的数据。我调用一个服务端点,它为我提供了3个对象。在每个对象中都有一个名为
的值。如果对象将此值设置为
Y
,则我希望将其添加到可用于单选按钮选项的数据集中。为了更好地解释,我在代码中添加了注释

这是我的密码

getLoanAdjustmentPreValidate() {
this.avafService.GetAVAFPreValidateLoanAdjustment(this.getAVAFPreValidateLoanAdjustmentRequest).subscribe((resp) => {
    //assign resp.loanAdjustmentResult.loanAdjustmentList to this.loanAdjustmentResult
    this.loanAdjustmentResult = resp.loanAdjustmentResult.loanAdjustmentList;
    //loop through this.loanAdjustmentResult to get which objects have restructureAllowed value as Y
    for (let i = 0; i < this.loanAdjustmentResult; i++) {
      //push values to this.loanAdjustmentResult
      if (this.loanAdjustmentResult[i].restructureAllowed == "Y") {
        this.loanAdjustmentResult.push({ "label": this.loanAdjustmentResult[i].restructureType, "checked": false, "name": "reduceoptionRadio" })
        console.log(this.loanAdjustmentResult);
      }
    }

  }, error => {
    ...
  });
}
看起来我的代码甚至没有进入控制台日志。任何想法,我可以做什么,或者如果我可以使问题更清楚,请让我知道

我在这里添加了一个stackblitz示例。我只是硬编码响应来代替服务调用
我已经修改了这个方法。你能试试这个吗

getLoanAdjustmentPreValidate() {
this.avafService.GetAVAFPreValidateLoanAdjustment(this.getAVAFPreValidateLoanAdjustmentRequest).subscribe(resp => {
    //assign resp.loanAdjustmentResult.loanAdjustmentList to this.loanAdjustmentResult
    this.loanAdjustmentResult = resp.loanAdjustmentResult.loanAdjustmentList;
    //loop through this.loanAdjustmentResult to get which objects have restructureAllowed value as Y
    for (let i = 0; i < this.loanAdjustmentResult.length; i++) {
      //push values to this.loanAdjustmentResult
      if (this.loanAdjustmentResult[i].restructureAllowed == "Y") {
        this.loanAdjustmentResult.push({ "label": this.loanAdjustmentResult[i].restructureType, "checked": false, "name": "reduceoptionRadio" })
        console.log(this.loanAdjustmentResult);
      }
    }

  }, error => {
    ...
  });
}
getLoanAdjustmentPreValidate(){
this.avafService.GetAVAFPreValidateLoanAdjustment(this.getAVAFPreValidateLoanAdjustmentRequest)。订阅(resp=>{
//将resp.loanAdjustmentResult.loanAdjustmentList分配给this.loanAdjustmentResult
this.loanAdjustmentResult=resp.loanAdjustmentResult.loanAdjustmentList;
//循环遍历this.loanAdjustmentResult以获取哪些对象的值为Y
for(设i=0;i{
...
});
}

假设您实际得到了响应,我猜
this.loanAdjustmentResult
为0,这导致
for(设I=0;I
立即终止。尝试将
this.loanAdjustmentResult
的值记录在
for
循环之前。@GreybearedGeek我确实看到了
this.loanAdjustmentResult=resp.loanAdjustmentResult.loanAdjustmentList之前的日志。我在for的
之后添加了另一个日志(让I=0;I
我在这里没有看到控制台日志我更新了我的评论-看一看我看到了for循环前
这个的值。loanAdjustmentResult
。我用stackblitz演示更新了我的问题。我只是硬编码了响应而不是服务调用。这在添加
(resp:Array)的地方出现了一个奇怪的错误
。没有重载匹配此调用。我添加了一个stackblitz。我只需硬编码响应,而不是服务调用。在上面给出的方法中,用resp代替(resp:Array),然后检查一个,让我知道我忘记了for循环中的
。length
:(是的,在我给出的方法中,.length被提及
getLoanAdjustmentPreValidate() {
this.avafService.GetAVAFPreValidateLoanAdjustment(this.getAVAFPreValidateLoanAdjustmentRequest).subscribe(resp => {
    //assign resp.loanAdjustmentResult.loanAdjustmentList to this.loanAdjustmentResult
    this.loanAdjustmentResult = resp.loanAdjustmentResult.loanAdjustmentList;
    //loop through this.loanAdjustmentResult to get which objects have restructureAllowed value as Y
    for (let i = 0; i < this.loanAdjustmentResult.length; i++) {
      //push values to this.loanAdjustmentResult
      if (this.loanAdjustmentResult[i].restructureAllowed == "Y") {
        this.loanAdjustmentResult.push({ "label": this.loanAdjustmentResult[i].restructureType, "checked": false, "name": "reduceoptionRadio" })
        console.log(this.loanAdjustmentResult);
      }
    }

  }, error => {
    ...
  });
}