这里是我在laravel应用程序中的html表单,它有隐藏字段,这些隐藏值需要发送到角度js控制器。隐藏的表单字段不能在角Js中工作
<form accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
<input name="user_id" type="hidden" value="{{ Auth::user()->id }}">
<input name="post_id" type="hidden" value="<% post.id %>" >
<input name="published_at" type="hidden" value="{{ Carbon\Carbon::today()->format('Y-m-d') }}">
<input class="form-control" placeholder="comment" ng-model="contentField" type="text" >
<button type="submit" ng-click="addComment()">comment</button>
</form>
我的角度控制器是如下
$scope.addComment = function(){
var comment = {
user_id: $scope.user_id,
content: $scope.contentField,
post_id: $scope.post_id,
published_at: $scope.published_at
};
我只得到contentField的值在控制器,请帮我解决这个问题!
我倾向于使用type =“hidden”和value =“..”来支持角度指令ng-hide =“true”和ng-model =“...”。设置值等于某些东西不会将其与角度模型绑定。另外,把你的评论变量放在$ scope中作为$ scope.comment并直接绑定到它,就像ng-model =“comment.user_id” – jbrown
还有其他方法可以在不使用ng-model的情况下发送隐藏表单值吗? –