【发布时间】:2016-09-23 10:13:56
【问题描述】:
我一直在尝试在 html 表单中使用 ngTagsInput 及其自动完成功能 (mbenford.github.io/ngTagsInput/demos) 来在 Mongodb 中提交食谱。
基本上,我使用带有自动完成功能的 ngTagsInput 来查询我的配料数据库并在“配方中的配料”中显示配料标签。
效果很好,直到我保存了食谱,但配料没有保存。
我知道问题出在哪里,但我还没有找到解决方案。 这是我添加食谱页面的“成分”字段,没有 ngTagsInput,只是一个普通的文本字段:
<div class="form-group">
<label for="ingredients">List of ingredients</label>
<input type="text" class="form-control" id="ingredients" ng-model="form.ingredients">
</div>
这里是使用 ngTagsInput 的“成分”字段(工作正常,但不保存):
<div class="form-group" ng-controller="recipeApiController">
<tags-input for="Ingredients" id="Ingredients" ng-model="tags" display-property="ingredientID" placeholder="Commence à taper le nom d'un ingrédient..." add-from-autocomplete-only="true">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
</div>
因为我将 ng-model="form.ingredients" 替换为使用 ngTagsInput 所需的 ng-model="tags",所以在单击“添加配方”按钮时不会保存这些成分标签。
这是我的 recipeApiController 的“保存到数据库”部分,用于“添加食谱”表单页面:
$scope.addToDatabase = function(){
RecipeApi.Recipe.save({}, $scope.form,
function(data){
$scope.recipe.push(data);
},
function(err){
bootbox.alert('Error: ' + err);
});
}
你知道我该如何解决这个问题并保存这些标签吗?
提前谢谢各位。我不希望这篇文章太长,但如果您需要更多信息、代码,我会非常积极地提供它。这对我有很大帮助。
【问题讨论】: