【发布时间】: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
-
不要改
<label>{{property.name}}</label>,把ng-disabled="{{attribute.selected}}"改成ng-disabled="attribute.selected"。 -
抱歉我的错字我的意思是选中
-
看起来
attribute.selected是undefined。也许您需要确保在作用域中定义了变量的默认值。
标签: angularjs angular-material