AngularJS不会发送隐藏字段值 [英] AngularJS does not send hidden field value

查看:1128
本文介绍了AngularJS不会发送隐藏字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于具体使用情况下,我必须提交一个表单的老办法。手段,我用一个形式的行动=。该响应流,所以我不重新加载页面。我完全知道,一个典型的应用AngularJS不会提交表单的方式,但到目前为止,我没有别的选择。

For a specific use case I have to submit a single form the "old way". Means, I use a form with action="". The response is streamed, so I am not reloading the page. I am completely aware that a typical AngularJS app would not submit a form that way, but so far I have no other choice.

这是说,我试图填充一些隐藏字段从角:

That said, i tried to populate some hidden fields from Angular:

<input type="hidden" name="someData" ng-model="data" /> {{data}}

请注意,在数据的正确值显示。

Please note, the correct value in data is shown.

的形式看起来像一个标准的形式为:

The form looks like a standard form:

<form id="aaa" name="aaa" action="/reports/aaa.html" method="post">
...
<input type="submit" value="Export" />
</form>

如果我打提交,没有值被发送到服务器。如果我改变输入字段中键入文本,它按预期工作。我的假设是隐藏字段是不是真的填充,而文本字段实际上是显示,由于双向结合。

If i hit submit, no value is sent to the server. If I change the input field to type "text" it works as expected. My assumption is the hidden field is not really populated, while the text field actually is shown due two-way-binding.

任何想法如何,我可以提交由居住AngularJS一个隐藏字段?

Any ideas how I can submit a hidden field populated by AngularJS?

推荐答案

您不能使用隐藏域的双结合。
的解决方案是使用括号

You cannot use double binding with hidden field. The solution is to use brackets :

<input type="hidden" name="someData" value="{{data}}" /> {{data}}

编辑:在Github上查看此主题:<一href=\"https://github.com/angular/angular.js/pull/2574\">https://github.com/angular/angular.js/pull/2574

编辑:

由于角1.2,你可以用'NG-值'指令到前pression绑定到输入的数值属性。该指令应与输入电台或复选框可以使用,但使用隐藏的输入效果很好。

Since Angular 1.2, you can use 'ng-value' directive to bind an expression to the value attribute of input. This directive should be used with input radio or checkbox but works well with hidden input.

下面是使用该解决方案NG-值:

Here is the solution using ng-value:

<input type="hidden" name="someData" ng-value="data" />

下面是一个使用NG-值与隐藏输入一个小提琴: http://jsfiddle.net/6SD9N

Here is a fiddle using ng-value with an hidden input: http://jsfiddle.net/6SD9N

这篇关于AngularJS不会发送隐藏字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆