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.presentPrice : 0)
}, state);
}, 0);
}
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