描述一下問題: 在操作表單中的隱藏域的時(shí)候發(fā)現(xiàn)angularjs的模型無法綁定,比如: <input type="hidden" name="someData" ng-model="data" /> 在網(wǎng)上找到了解決辦法,特意記錄;原文:http:///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" />
最優(yōu)回答如下: You cannot use double binding with hidden field. The solution is to use brackets :
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:
Here is a fiddle using ng-value with an hidden input: http:///6SD9N
|
|