与角度js的模型绑定

时间:2013-11-27 10:43:23

标签: asp.net-mvc-3 angularjs

我正在尝试使用angular js为复选框进行模型绑定。复选框值正确绑定,但它不显示为选中的偶数值对于复选框是真的。

以下是代码

<input type="checkbox" id="checkboxDontKnowWaistSize" required value="True" ng-value="True" name="ServiceObject.DontKnowWaistSize"  data-ng-model="BodyMassIndexForm.DontKnowWaistSize" class="checkbox"  data-ng-init="BodyMassIndexForm.DontKnowWaistSize=True" >

1 个答案:

答案 0 :(得分:0)

尝试ng-checked属性:

从角度1.2.1源代码中提取:

@description
 * The HTML specification does not require browsers to preserve the values of boolean attributes
 * such as checked. (Their presence means true and their absence means false.)
 * This prevents the Angular compiler from retrieving the binding expression.
 * The `ngChecked` directive solves this problem for the `checked` attribute.
 * @example
    <doc:example>
      <doc:source>
        Check me to check both: <input type="checkbox" ng-model="master"><br/>
        <input id="checkSlave" type="checkbox" ng-checked="master">