以下のソース中の配列:fixCostListの要素取得の方法について質問です。
fixCostList[0]で0番目の要素を取得しようと思っているのですが、undefinedとなり取得できません。
例えば、fixCostList[0].amountと記述すれば、"1000"が取得できる想定だったのですが。。。
要素の取得方法について、どなたか教えていただけないでしょうか。
ts:home.ts
1import { Component, ViewChild } from '@angular/core'; 2import { NavController } from 'ionic-angular'; 3import { ActionSheetController } from 'ionic-angular'; 4import { AngularFireDatabase } from 'angularfire2/database'; 5 6@Component({ 7 selector: 'page-home', 8 templateUrl: 'home.html', 9}) 10 11export class HomePage { 12 constructor(public navCtrl: NavController, public actionsheetCtrl: ActionSheetController, 13 public afdb: AngularFireDatabase) { 14 15 // (省略) 16 17 } 18 19 getBopData(list, year, month, dayCount) { 20 21 // (中略) 22 23 // 固定費計算 24 let fixCostList = []; 25 // 固定費リストを取得 26 this.afdb.list('fixedCost') 27 .subscribe(list => { 28 list.forEach(item => { 29 fixCostList.push(item); 30 }) 31 }); 32 33 // ログにundefinedと出力されてしまう 34 console.log(fixCostList[0]); 35 36 // (以下省略)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/14 03:37