ng-disabled似乎不起作用

时间:2022-07-26 18:54:39

I'm trying to conditionally enable/disable my Save button using ng-disabled:

我正在尝试使用ng-disabled有条件地启用/禁用我的保存按钮:

<button type="button" title="Save Changes" ng-click="onSaveChanges()" ng-disabled="{{!data.modified}}">Save</button>

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.

我有一个$ scope.data.modified变量,当我的数据被修改时,该变量变为true。无论是真还是假,都会启用“保存”按钮。元素检查显示ng-disabled的值按预期在“true”和“false”之间切换,但按钮始终处于启用状态。

1 个解决方案

#1


24  

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}}

当你使用角度js属性(如ng-show,ng-hide,ng-disabled)时,它应该没有蛇符号Ex.ng-disabled =“!data.modified”。对于其他普通属性,如class,id,你必须使用蛇符号。防爆。类= {{aVaribaleinControllerScope}}

#1


24  

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}}

当你使用角度js属性(如ng-show,ng-hide,ng-disabled)时,它应该没有蛇符号Ex.ng-disabled =“!data.modified”。对于其他普通属性,如class,id,你必须使用蛇符号。防爆。类= {{aVaribaleinControllerScope}}