在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ Angular4 reduce 價格累加報錯

Angular4 reduce 價格累加報錯

麻煩幫忙看一下

報錯信息:

谷歌Chrome:

Error TypeError: Cannot read property 'reduce' of  undefined
at checkAndUpdateView(core.es5.js:12241)


火狐Firefox:

TypeError: this.shoppingcartList is undefined
MallShoppingCartComponent.prototype.getTotal@http://localhost:4200/0.chunk.js:1408:9

============================

代碼片段(shopingcartList 就是返回的數(shù)據(jù)列表):

public shoppingcarList: any;

ngOnInit(){
this.getMockTest();
}

getMockTest(){
this.ishoppingcarApi.getLIstUsingGET().subscribe(
  result => {
    this.shopingcartList =result;
    ... ...
}


getTotal(){        // 價格累加
return this.shoppingcartList.reduce((state, order) =>{
 return order.cartCommodities.reduce((state,courseList => {
return state + (courseList.checked ? courseList.price ? courseList.price.presentPrice : 0);
}, state);

}, 0);
}


html 模板中
{{getTotal()}}
回答
編輯回答
尕筱澄

shoppingcartList未定義,你沒有賦值

2017年3月1日 15:46