Is there a way to create an array on each diary object and push foods that match the diary id to that array? Can anyone suggest improvements or identify reasons why it may not be working?
(Diary Controller)
app.controller("DiaryCtrl", function($scope, $rootScope, $location, DiaryFactory, FoodFactory){
$scope.diaries = [];
$scope.foods = [];
//getMeals
//lists all meals on the diary page
let getAllDiaries = function(){
DiaryFactory.getDiary($rootScope.user.uid).then(function(FbDiaries) {
console.log('diaries: ', FbDiaries);
FoodFactory.getFoodsFB($rootScope.user.uid).then(function(FbFoods){
console.log('foods from controller', FbFoods);
FbFoods.forEach(function(food){
FbDiaries.forEach(function(diary){
console.log('foods', food);
if(food.mealId === diary.id){
diary.foods.push(food);
console.log('foods array on diary', diary.foods);
}
});
});
});
});
};
getAllDiaries();