双向数据绑定不适用于数据-ng-disabled

时间:2015-05-13 23:27:32

标签: angularjs ionic

我怎样才能btnDisabled更改即时功能范围内的data-ng-disabled,但在我的ajax 成功范围内,没有什么能够很好地发挥作用。如何让我的按钮禁用

JS

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

HTML

<button data-ng-disabled="{{ btnDisabled }}" class="button button-block green">redeem coupon</button>

注意

我注意到,当我通过 ajax success 范围更新变量时,我的双向数据绑定都不起作用。有没有办法克服这个问题?

2 个答案:

答案 0 :(得分:3)

ngDisabled expects表达式,而不是字符串(插值始终输出字符串值):

<button data-ng-disabled="btnDisabled" 
        class="button button-block green">redeem coupon</button>

Working Plunker

答案 1 :(得分:0)

更改

data-ng-disabled 

ng-disabled