【问题标题】:ng-disabled not affecting input enabled/disabled when being changed [duplicate]ng-disabled在更改时不影响启用/禁用输入[重复]
【发布时间】:2016-03-23 07:00:39
【问题描述】:

我正在尝试在输入(文本或数字)上使用 ng-disabled

<input ng-disabled="{{attribute.selected}}"...

当绑定到复选框时,我已经看到它可以工作,但我似乎无法在这里工作。

我尝试不使用 {{}},但标记只包含“attribute.selected”而不是 true 或 false

单击 md 复选框时,我可以在 chrome 开发工具中看到该值正在更改。 ng-disabled="true" 然后 ng-disabled="false"

使用 !attribute.selected 时,输入被禁用,当值变为 true 时不会重新启用。

完整的sn-p:

    <md-content layout-padding layout-xs="column">
        <md-checkbox md-ink-ripple="#2199FF" id="attr{{attribute.id}}" ng-model="attribute.selected">
            {{attribute.name}}
        </md-checkbox>

        <md-content layout-padding ng-repeat="property in attribute.properties">

            <md-input-container >
                <label>{{property.name}}</label>
                <input ng-disabled="{{attribute.selected}}" md-maxlength="{{property.maxLength}}" type="{{property.type}}" required name="{{property.name}}" ng-model="property.value">
                <div ng-messages="Required">
                    <div ng-message="required">This is required.</div>
                    <div ng-message="md-maxlength">Max {{property.maxLength}} digits</div>
                </div>
            </md-input-container>

        </md-content>
    </md-content>

</div>

【问题讨论】:

  • 您不应该需要禁用 ng 的 {{}}。这是自动插值的
  • 我试过没有 {{}} 它在 html 中显示 property.name
  • 不要改&lt;label&gt;{{property.name}}&lt;/label&gt;,把ng-disabled="{{attribute.selected}}"改成ng-disabled="attribute.selected"
  • 抱歉我的错字我的意思是选中
  • 看起来attribute.selectedundefined。也许您需要确保在作用域中定义了变量的默认值。

标签: angularjs angular-material


【解决方案1】:

将 ng-disabled="{{attribute.selected}}" 更改为 ng-disabled="attribute.selected"

<md-content layout-padding layout-xs="column">
    <md-checkbox md-ink-ripple="#2199FF" id="attr{{attribute.id}}" ng-model="attribute.selected">
        {{attribute.name}}
    </md-checkbox>

    <md-content layout-padding ng-repeat="property in attribute.properties">

        <md-input-container >
            <label>{{property.name}}</label>
            <input ng-disabled="attribute.selected" md-maxlength="{{property.maxLength}}" type="{{property.type}}" required name="{{property.name}}" ng-model="property.value">
            <div ng-messages="Required">
                <div ng-message="required">This is required.</div>
                <div ng-message="md-maxlength">Max {{property.maxLength}} digits</div>
            </div>
        </md-input-container>

    </md-content>
</md-content>

【讨论】:

  • 我会再试一次。但是如上所述我已经尝试过了。
  • 能不能把vue中的值打印出来给我结果
    {{属性| json }}
  • 道歉一个和所有.. 完全有效.. 我一直关注 html 中的字符串 !attribute.selected 而不是 true 或 false .. 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 2017-07-14
  • 2017-04-16
  • 1970-01-01
相关资源
最近更新 更多