Reputation: 554
I want to pass recipe and ingredients scope through the ng-click function createRecipe(). I declared the ingredients as array.
$scope.ingredients = [];
$scope.recipe = {};
then in my html, I have inputs that have $index
<input type="text" class="form-control" id="RecipeName" name="RecipeName" required ng-model="recipe.Name">
<input type="text" class="form-control" id="IngredientQuantity" name="IngredientQuantity" ng-model="ingredients.Quantity[$index+1]" />
then when user clicks submit I need to get both scopes
<input type="submit" value="Create" class="btn btn-default" ng-click="createRecipe(recipe;ingredients)"/>
I will be referencing the recipeid in my ingredients table so I need them in one funtion.
$scope.createRecipe = function (recipe) {
$scope.uploader.uploadAll();
$http({
method: 'POST',
url: '/Recipes/CreateRecipe',
data: $scope.recipe
}).then(function (response) {
var recipeID = response.data;
var vmRecipeIng = {
Quantity: $scope.ingredients.Quantity,
UOM: $scope.ingredients.UOM,
Name: $scope.ingredients.Name,
RecipeId: recipeID
};
vmRecipeIngs = vmRecipeIng;
alert(vmRecipeIng);
console.log(vmRecipeIng);
$http({
method: 'POST',
url: '/RecipeIngredients/CreateRecipeIngredient',
data: vmRecipeIng
}).then(function (response) {
}, function () { alert('Error CreateRecipeIngredient'); });
}, function () { alert('Error CreateRecipe'); });
};
Upvotes: 0
Views: 65
Reputation: 222700
Your function needs to have two parameters since your HTML passes two,
$scope.createRecipe = function (recipe,ingredient) {
}
also the function should have parameters separated by ,
not ;
<input type="submit" value="Create" class="btn btn-default" ng-click="createRecipe(recipe,ingredients)">
Upvotes: 2