【问题标题】:Model binding with angular js使用 Angular js 进行模型绑定
【发布时间】:2013-11-27 10:43:23
【问题描述】:

我正在尝试使用 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" >

【问题讨论】:

    标签: asp.net-mvc-3 angularjs


    【解决方案1】:

    试试 ng-checked 属性:

    从 Angular 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">
    

    【讨论】:

    • 你有进步吗?
    猜你喜欢
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多