Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

javascript - AngularJS不发送隐藏字段值(AngularJS does not send hidden field value)

For a specific use case I have to submit a single form the "old way".(对于特定用例,我必须以“旧方式”提交单个表单。)

Means, I use a form with action="".(意思是,我使用带有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.(我完全知道一个典型的AngularJS应用程序不会以这种方式提交表单,但到目前为止我别无选择。) That said, i tried to populate some hidden fields from Angular:(也就是说,我试图从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.(如果我将输入字段更改为键入“text”,它将按预期工作。) My assumption is the hidden field is not really populated, while the text field actually is shown due two-way-binding.(我的假设是隐藏字段没有真正填充,而文本字段实际上是由于双向绑定显示的。) Any ideas how I can submit a hidden field populated by AngularJS?(有关如何提交由AngularJS填充的隐藏字段的任何想法?)   ask by Christian translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot use double binding with hidden field.(您不能对隐藏字段使用双重绑定。)

The solution is to use brackets :(解决方案是使用括号:) <input type="hidden" name="someData" value="{{data}}" /> {{data}} EDIT : See this thread on github : https://github.com/angular/angular.js/pull/2574(编辑:在github上看到这个帖子: https//github.com/angular/angular.js/pull/2574) EDIT:(编辑:) Since Angular 1.2, you can use 'ng-value' directive to bind an expression to the value attribute of input.(从Angular 1.2开始,您可以使用'ng-value'指令将表达式绑定到input的value属性。) This directive should be used with input radio or checkbox but works well with hidden input.(该指令应与输入无线电或复选框一起使用,但适用于隐藏输入。) Here is the solution using ng-value:(以下是使用ng值的解决方案:) <input type="hidden" name="someData" ng-value="data" /> Here is a fiddle using ng-value with an hidden input: http://jsfiddle.net/6SD9N(这是一个使用带有隐藏输入的ng值的小提琴: http//jsfiddle.net/6SD9N)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...