我是Angular JS和mongod的新手。我希望能够将新的成分字段推入此页面,以便按下+按钮。
这是我的观点
这是我的.jade文件 block content
div.container-fluid(ng-controller="DrinkController", ng-init="setDrinks( #{JSON.stringify(drinks)} )")
div.row
div.col-md-2
div.col-md-8
h1.title Edit Drinks
div.row
div.col-md-3
b Name
div.col-md-3
b Filename
div.col-md-1
div.col-md-5
b Ingredients
div.row.editRow(ng-repeat="drink in drinks | orderBy: 'name'")
form(ng-submit="editDrink(drink)")
div.col-md-3
input(value="{{drink.name}}", ng-model="drink.name")
div.col-md-3
input(value="{{drink.image}}", ng-model="drink.image")
div.col-md-1.text-right
a(ng-click="addNewIngredientEd()") +
div.col-md-4
div.row(ng-repeat="ingredient in drink.ingredients")
div.col-md-7
select.mixers(value="{{ingredient.name}}", ng-model="ingredient.name", ng-options="i for i in ingredientsList")
div.col-md-4
input.addForm.ingredient(value="{{ingredient.amount}}", ng-model="ingredient.amount", style="width: 100px;")
div.col-md-1
a(ng-click="removeIngredientEdit($index)") -
div.col-md-1
button.btn Save
这是我的相关JS
$scope.addNewIngredientEd = function () {
$scope.newDrink.ingredients.push({ name: '', amount: 0 });
//alert("Hello! I am an alert box!!");
console.log('Added new ingredient Test ');
};
答案 0 :(得分:0)
您想要$index
,它是ng-repeat
addNewIngredientEd($index)
和
$scope.addNewIngredientEd = function ($index) {
$scope.drinks[$index].ingredients.push(...