无法设置属性' 3'未定义的

时间:2018-02-12 14:46:26

标签: arrays json angular typescript

我收到此错误以使用此代码创建对象。

let i = 0;
adminItems.forEach(adminItem => {
    this.coinmarketService.getDataByName(adminItem.coinname)
    .subscribe(response => {
        let coinItem = response.json();
        this.items[i] = {
            'name': coinItem[0].name,
            'symbol': coinItem[0].symbol,
            'price_usd': coinItem[0].price_usd,
            'price_btc': coinItem[0].price_btc,
            'percent_change_24h_usd': coinItem[0].percent_change_24h,
            'percent_change_24h_btc': coinItem[0].percent_change_24h,
            'percent_btc': ((1 / coinItem[0].price_btc) * 100),
            'percent_potential': adminItem.percentage,
            'description': adminItem.description
        };
        console.log(this.items);
    });
    i++;
});

这是详细错误:

  

错误类型错误:无法设置属性' 3'未定义的       在SafeSubscriber.eval [as _next](dashboard.component.ts:32)       在SafeSubscriber .__ tryOrUnsub(Subscriber.js:239)       在SafeSubscriber.next(Subscriber.js:186)       在Subscriber._next(Subscriber.js:127)       在Subscriber.next(Subscriber.js:91)       在XMLHttpRequest.onLoad(http.es5.js:1226)       在ZoneDelegate.invokeTask(zone.js:425)       at Object.onInvokeTask(core.es5.js:3881)       在ZoneDelegate.invokeTask(zone.js:424)       在Zone.runTask(zone.js:192)

0 个答案:

没有答案