Closed cmurnick closed 6 years ago
something like this from the favoriteCtrl and do from searchCtrl too
$scope.addToMenu = (recipe) => {
recipe.uid = AuthService.getCurrentUid();
recipe.onMenu = true;
let updatedRecipe = RecipeService.createRecipeObject(recipe);
RecipeService.updateRecipe(updatedRecipe, recipe.id).then((result) => {
}).catch((err) => {
console.log("error in update movie", err);
});
};
$scope.switchHasIngredient = (ingredient, hasIngredient) => {
ingredient.hasIngredient = hasIngredient;
let updatedIngredient = IngredientService.createIngredientObject(ingredient);
IngredientService.updateIngredient(updatedIngredient, ingredient.id).then((result) => {
getIngredients();
}).catch((err) => {
console.log("error in update ingredient", err);
});
};
}
then this to the ingredientService.js file:
const updateIngredient = (ingredient, ingredientId) => {
return $http.put(`${FIREBASE_CONFIG.databaseURL}/ingredient/${recipeId}.json`, JSON.stringify(ingredient));
};
-Have to change the ingredientObject that is created in ingredient service and when make the API call, set hasIngredient=false
<p ng-if="!contact.favorite">
<i class="fa fa-star-o fa-lg" aria-hidden="true" ng-click="switchFavorite(contact, true)"></i>
</p>
<p ng-if="contact.favorite">
<i class="fa fa-star fa-lg" aria-hidden="true" ng-click="switchFavorite(contact, false)"></i>
</p>
WHEN the individual clicks the checkbox that they have the ingredient in the grocery page THEN firebase is updated so hasIngredient= true