我怎样才能btnDisabled
更改即时功能范围内的data-ng-disabled
,但在我的ajax
成功范围内,没有什么能够很好地发挥作用。如何让我的按钮禁用?
.controller('CouponCtrl', function($http, $scope) {
$scope.btnDisabled = false;
// $scope.btnDisabled = true; // this works fine too
$http.jsonp("someurl?_jsonp=JSON_CALLBACK").success(function(){
$scope.btnDisabled = true; // does not work
console.log("I see this so why doesn't my button disable?");
// $scope.$digest(); // tried this too but I'm told digest is already running
}
}
<button data-ng-disabled="{{ btnDisabled }}" class="button button-block green">redeem coupon</button>
注意
我注意到,当我通过 ajax success 范围更新变量时,我的双向数据绑定都不起作用。有没有办法克服这个问题?
答案 0 :(得分:3)
ngDisabled
expects表达式,而不是字符串(插值始终输出字符串值):
<button data-ng-disabled="btnDisabled"
class="button button-block green">redeem coupon</button>
答案 1 :(得分:0)
更改
data-ng-disabled
到
ng-disabled