angularjs 的模型无法绑定到隐藏域(input hidden)
描述一下问题:
在操作表单中的隐藏域的时候发现angularjs的模型无法绑定,比如:
<input type="hidden" name="someData" ng-model="data" />
在网上找到了解决办法,特意记录;原文:http://stackoverflow.com/questions/18446359/angularjs-does-not-send-hidden-field-value
这种通常情况下data一直无法取到值;
有以下几种解决办法:
1,
<input type="text" name="someData" ng-model="data" style="display: none;"/>
2,
<input type="hidden" required ng-model="data.userid" ng-init="data.userid=pivot.id" />
3,
<input type="hidden" name="someData" value="{{data}}" />
4,
<input type="hidden" name="someData" ng-value="data" />
最优回答如下:
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
EDIT:
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.
Here is the solution using ng-value:
<input type="hidden" name="someData" ng-value="data" />
Here is a fiddle using ng-value with an hidden input: http://jsfiddle.net/6SD9N
angularjs 的模型无法绑定到隐藏域(input hidden)的更多相关文章
- bootstrapValidator对于隐藏域验证和程序赋值即时验证的问题
问题1: 如下代码: <input type="hidden" name="productId"/> $("#addForm") ...
- 隐藏域传值到后台controller
开发背景:一个页面有一个下拉框和一个单选按钮,下拉框保存的是厂商信息,单选按钮保存的是产品信息.每次下拉框的内容被选中,把厂商编码保存到隐藏域 <input type="hidden& ...
- AngularJS:模型
ylbtech-AngularJS:模型 1.返回顶部 1. AngularJS ng-model 指令 ng-model 指令用于绑定应用程序数据到 HTML 控制器(input, select, ...
- jquery.validate 使用--验证表单隐藏域
jQuery validate很不错的一个jQuery表单验证插件.升级到了1.9版的后,发现隐藏表单域验证全部失效,特别是在jquery.ui.tabs.min.js构造的Tabs里的验证. 是因为 ...
- html中隐藏域hidden的作用介绍及使用示例
基本语法: <input type="hidden" name="field_name" value="value"> 作用: ...
- 避免url传值字符串sjstr过长,使用from表单【隐藏域】post提交
1.普通的url传值<html--------------- <!-- 隐藏域post提交url --> <form id="urlPost" action ...
- 错误记录:html隐藏域的值存字符串时出错
问题 webform在后台给前台传值. <input type="hidden" value="<%=userType %>" id=&qu ...
- [Asp.Net]状态管理(Session、Application、Cache、Cookie 、Viewstate、隐藏域 、查询字符串)
Session: 1. 客户在服务器上第一次打开Asp.Net页面时,会话就开始了.当客户在20分钟之内没有访问服务器,会话结束,销毁session.(当然也可以在Web.config中设置缓存时间 ...
- html中隐藏域hidden的作用
基本语法: <input type="hidden" name="field_name" value="value"> 作用: ...
随机推荐
- [Java] 项目红色叹号 案例1则
一般红色叹号是build path出错. 除了检查出错的library外,还要注意Order an Export选项中未勾选的Library. 之前导入项目后,没有勾选JRE和Maven Depend ...
- 『TensorFlow』张量拼接_调整维度_切片
1.tf.concat tf.concat的作用主要是将向量按指定维连起来,其余维度不变:而1.0版本以后,函数的用法变成: t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, ...
- MVC实战之排球计分(七)——软件的具体实现与测试
在前面的几篇博客中咱们已经写过了软件的大概实现,在这篇博客中将讲述此软件的具体实现与测试. 1,新建一个项目,命名为:Volleyball,选择基本模板.如图: 点击确定.创建项目. 2,右键单击mo ...
- "她等待刀尖已经太久"--茨维塔耶娃诗抄
生活 1 你无法夺走我的红晕—— 它强大——如同河水的汛潮! 你是猎人,可我不会上当, 你若追逐,我就会逃跑. 你无法夺走我鲜活的灵魂! 就这样,在急遽的追逐中—— 一匹阿拉伯的骏马, 微 ...
- 错误:Bean property 'sessionFactory' is not writable or has an invalid setter method.
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' ...
- .net core WebApi Monitor实现并发同步
在.net中,还可以使用Monitor实现线程并发同步.Monitor类是纯托管且完全可移植,并且可能会在操作系统资源需求方面更加高效. Monitor的锁对象尽可能使用引用对象,如果是字符串或值对象 ...
- [Leetcode 18]四数之和 4 Sum
[题目] Given an array nums of n integers and an integer target, are there elements a, b, c, and d in n ...
- jq demo 九宫格抽奖
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- spring boot 项目插入数据后,返回数据库自增主键
在对应的实体上添加@GeneratedValue(generator = "JDBC"),如下所示 @GeneratedValue(generator = "JDBC&q ...
- centos 安装桌面系统
yum -y groupinstall "Desktop" "Desktop Platform" "X Window System" &qu ...