ngDisabled和ngClick不能一起工作
问题描述:
我有这种形式:ngDisabled和ngClick不能一起工作
<div class="form-group">
<label for="GrpName"> Mail:</label>
<input ng-model="customerToUpdate.mail" type="text" class="form-control" id="name">
<button type="button" class="btn btn-default" ng-click="loadCustomer()">
Load
</button>
</div>
<div class="form-group">
<label for="GrpName"> Username:</label>
<input ng-disabled="{{isDisabled}}" ng-model="customerToUpdate.username" type="text" class="form-control" id="name">
</div>
控制器:
$scope.isDisabled = true;
$scope.loadCustomer = function() {
Customer.getByEmail($scope.customerToUpdate.mail)
.success(function(customer, status, headers, config) {
if(!isEmptyObject(customer)){
$scope.isDisabled = false;
}else
$scope.isDisabled = true;
});
};
使用Chrome,我可以检查并看到ng-disabled
改为true
和false
但没有UI更新。我也试过readonly
代替,但相同的结果..
我失去了一些东西?
答
NG-禁用is bound with '=' not with '@',所以你不应该使用括号:
把你
<input ng-disabled="{{isDisabled}}" ng-model="customerToUpdate.username" type="text" class="form-control" id="name">
到
<input ng-disabled="isDisabled" ng-model="customerToUpdate.username" type="text" class="form-control" id="name">
,它应该工作!
+0
我已经解决了,谢谢,你能在这个问题下看我的评论吗? –
+0
当然我可以:-)如果你接受我的回答,我会很高兴:-) – hoeni
答
之后所进行的HTTP请求,并在变更后$范围回调,你必须使用 $范围$适用()。 强制反射鉴于
应NG-禁用= “isDisabled” –
解决了,可你让一个答案?我不明白区别..为什么ng-disabled在检查模式下更改为true和false,但在UI中没有更改? –
总结:ng-disabled使用'=',所以你必须传递变量(不是值),否则指令失败并且什么也不做,所以它仍然是ng-disabled =“...”(不是disabled =“...” ) –