描述一下问题:

在操作表单中的隐藏域的时候发现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)的更多相关文章

  1. bootstrapValidator对于隐藏域验证和程序赋值即时验证的问题

    问题1: 如下代码: <input type="hidden" name="productId"/> $("#addForm") ...

  2. 隐藏域传值到后台controller

    开发背景:一个页面有一个下拉框和一个单选按钮,下拉框保存的是厂商信息,单选按钮保存的是产品信息.每次下拉框的内容被选中,把厂商编码保存到隐藏域 <input type="hidden& ...

  3. AngularJS:模型

    ylbtech-AngularJS:模型 1.返回顶部 1. AngularJS ng-model 指令 ng-model 指令用于绑定应用程序数据到 HTML 控制器(input, select, ...

  4. jquery.validate 使用--验证表单隐藏域

    jQuery validate很不错的一个jQuery表单验证插件.升级到了1.9版的后,发现隐藏表单域验证全部失效,特别是在jquery.ui.tabs.min.js构造的Tabs里的验证. 是因为 ...

  5. html中隐藏域hidden的作用介绍及使用示例

    基本语法: <input type="hidden" name="field_name" value="value"> 作用:  ...

  6. 避免url传值字符串sjstr过长,使用from表单【隐藏域】post提交

    1.普通的url传值<html--------------- <!-- 隐藏域post提交url --> <form id="urlPost" action ...

  7. 错误记录:html隐藏域的值存字符串时出错

    问题 webform在后台给前台传值.  <input type="hidden" value="<%=userType %>" id=&qu ...

  8. [Asp.Net]状态管理(Session、Application、Cache、Cookie 、Viewstate、隐藏域 、查询字符串)

    Session:  1. 客户在服务器上第一次打开Asp.Net页面时,会话就开始了.当客户在20分钟之内没有访问服务器,会话结束,销毁session.(当然也可以在Web.config中设置缓存时间 ...

  9. html中隐藏域hidden的作用

    基本语法: <input type="hidden" name="field_name" value="value"> 作用: ...

随机推荐

  1. npm 是干什么的

    网上的 npm 教程主要都在讲怎么安装.配置和使用 npm,却不告诉新人「为什么要使用 npm」.今天我就来讲讲这个话题. 本文目标读者是「不太了解 npm 的新人」,大神您别看了,不然又说我啰嗦了 ...

  2. postman(三):添加断言

    进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致 进行接口测试时,添加断言时必不可少的,断言就是判断响应内容与预期返回是否一致   postman可以在请求模块的Tests ...

  3. 无头浏览器phantomJS

    selenium: 有头浏览器的代表(selenium+python也可实现静默运行 引入python的一个包,包叫:虚拟屏幕pyvirtualdisplay) PhantomJS : 无头浏览器的代 ...

  4. Dubbox:来自当当网的SOA服务框架

    Dubbox:来自当当网的SOA服务框架 http://www.open-open.com/lib/view/open1417426480618.html

  5. python学习:数据类型

    python有两种索引方式.一种从左至右,下标从0开始:一种从右至左,下标从-1开始. python有六种数据类型: 不可变数据(四个):Number(数字).String(字符串).Tuple(元组 ...

  6. MongoDB数据库基本命令

    MongoDB的启动 先找到MongoDB所在的路径,然后执行以下代码 mongod --dbpath=E:\Program Files\MongoDB\Server\3.4\data\db --db ...

  7. vsto-Word相关操作

    //添加页码到页脚 Document doc = Globals.ThisAddIn.Application.ActiveDocument; HeaderFooter hprimary= doc.Se ...

  8. js利用sort()方法实现数组排序

    1.number类型排序 let aa = [1,11,2,4,3] aa.sort() console.log(aa) //[1,11,2,3,4] aa.sort((a,b)=>a-b) c ...

  9. decltype typename

    decltype((variable))总是引用类型,但是decltype(variable)只有当variable是引用类型时才是引用类型. #include <iostream> #i ...

  10. 如何加快C++代码的编译速度 转 ccache

    http://www.cnblogs.com/baiyanhuang/archive/2010/01/17/1730717.html   C++代码一直以其运行时的高性能高调面对世人, 但是说起编译速 ...