我在模板HTML中隐藏了输入:
<input type="hidden" name="idNote" value="{{formSpam.idNote}}" ng-model="formSpam.idNote" required>
控制器中的方法,它接受一个参数并将此值赋给formSpam.idNote
:
$scope.ClickSpam = function (id){
$scope.formSpam.idNote = id;
}
但是在属性value
的模板中,当我发送表单时,这是空的。为什么呢?
已完成的代码:
<div class="spam-icon ng-scope" data-dismiss="modal" ng-controller="SpamController" ng-click="ClickSpam(22, 1);" data-toggle="modal" data-target="#spamModal"></div>
在底部页面中显示此HTML:
<div class="modal fade spam-modal" id="spamModal" ng-controller="SpamController" tabindex="-1" role="dialog" aria-hidden="true">
<input type="hidden" name="idNote" ng-value="formSpam.idNote" ng-model="formSpam.idNote" required>
</div>
答案 0 :(得分:5)
使用ng-value: -
<input type="hidden" name="idNote" ng-value="formSpam.idNote" ng-model="formSpam.idNote" required>
还有一件事就是不需要在隐藏字段上使用必需和ng模型,您可以通过以下方式完成: -
<input type="hidden" name="idNote" ng-value="formSpam.idNote">
$scope.ClickSpam = function (id){
$scope.formSpam.idNote = id;
}