始终启用 ng-disabled 的按钮 [英] button with ng-disabled always enabled
问题描述
我正在尝试使用 ng-disabled 有条件地启用/禁用我的保存按钮:
I'm trying to conditionally enable/disable my Save button using ng-disabled:
<button type="button" title="Save Changes" ng-click="onSaveChanges()"
ng-disabled="{{!data.modified}}">
Save
</button>
我有一个 $scope.data.modified 变量,当我的数据被修改时,它会变为 true.无论这是对还是错,都启用了保存"按钮.元素检查显示 ng-disabled 的值按预期在true"和false"之间切换,但按钮始终处于启用状态.
I have a $scope.data.modified variable that changes to true when my data has been modified. Regardless whether that is true or false, the Save button is enabled. Element inspection reveals that the value of ng-disabled toggles between "true" and "false" as expect but the button is always enabled.
推荐答案
当您使用 angular js 属性(如 ng-show、ng-hide、ng-disabled)时,它应该没有蛇符号 Ex.ng-disabled="!data.modified"
.对于其他普通属性,如 class、id,您必须将其与蛇形符号一起使用.前任.class={{aVaribaleinControllerScope}}
when you are using a angular js attribute (like ng-show, ng-hide, ng-disabled) it should be without the snake notation Ex.ng-disabled="!data.modified"
. For other ordinary attribute like class, id you have to use it with the snake notation. Ex. class={{aVaribaleinControllerScope}}
这篇关于始终启用 ng-disabled 的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!