简体   繁体   English

如何使用Angular.js将隐藏文件添加到表单

[英]How to add hidden filed to form with Angular.js

I have several divs in my html. 我的html中有几个div。

<div ng-click="remeber_gift({{gift.id}})">div1</div>
<div ng-click="remeber_gift({{gift.id}})">div2</div>
<div ng-click="remeber_gift({{gift.id}})">div3</div>

I want to add hidden filed to clicked div with angular.js and remove all other hidden fields from other divs. 我想使用angular.js向单击的div添加隐藏文件,并从其他div删除所有其他隐藏字段。

Is this possible at all to do with Angular.js ? 这与Angular.js完全可能吗? In jquery simple .append is enough. 在jquery中,简单的.append就足够了。

You might be able to.. but it wouldn't be very clear or succinct Angular code. 您可能可以..但是它不是很清楚或简洁的Angular代码。 You want to avoid DOM manipulation like this as much as you can with Angular. 您希望尽可能避免使用Angular这样的DOM操作。 If you need to have a hidden field with a gift id, you could have just one in your view and ng-bind it to a variable in your scope. 如果您需要一个带有礼物ID的隐藏字段,则视图中可以只有一个,并将其ng-bind绑定到您范围内的变量。

ex <input type="hidden" ng-bind="saved_gift" /> 例如<input type="hidden" ng-bind="saved_gift" />

Then your remeber_gift function could just update that saved_gift to the selected gift.id . 然后,您的remeber_gift函数可以将该saved_gift更新为所选的gift.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM