Angular 4 - 将新的API响应插入API响应中

时间:2017-10-02 17:27:09

标签: javascript angular api typescript asynchronous

我有一个简单的异步.NET API设置,我正在尝试在我的TypeScript组件中收集数据。我正在填充customerTransactions并尝试将transactionDetails插入其中。

我的代码如下:

this.apiService.GetCustomerTransactions(this.customerNumber, startDate, endDate).subscribe(
    customerTransactions => {
        this.customerTransactions = customerTransactions;
        this.orderCount = this.customerTransactions.length;

        for (var i = 0; i < this.customerTransactions.length; i++) {
           this.apiService.GetCustomerTransactionDetails(this.customerNumber, this.customerTransactions[i].storeNumber, this.customerTransactions[i].transactionNumber).subscribe(
               customerTransactionDetails => {
                   this.customerTransactions[i].transactionDetails = customerTransactionDetails;
                   //console.log(customerTransactionDetails);
               }
           );
        }
        //console.log(this.customerTransactions);
    }
);

让我感到困惑的部分是为什么注释掉的console.log正在返回预期的响应,但是当我尝试将它添加到我现有的数组时,我遇到了问题并且遇到了“ERROR TypeError:无法设置属性”控制台中每行的“未定义”消息的“transactionDetails”。

非常感谢您的帮助!

0 个答案:

没有答案