最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ng-disabled not working with bootstrap buttons - Stack Overflow

programmeradmin2浏览0评论

I am using bootstrap.js along with angular js, my code is following-

//few lines from controller
$scope.isWaiting = true;
$scope.promise = $http.get("voluumHandler.php?q=campaigns&filter=traffic-source&filterVal=" + traffic + "&from=" + from + "&to=" + to + "&tz=" + tz).success(function(response){        
        $scope.campaigns = response.rows;
        console.log(response.rows);
        $scope.isWaiting = false;
    }).error(function(response){
        alert(response);
        $scope.isWaiting = false;
    });

Here isWaiting is used for disabling and enabling the button.

<!--HTML -->
<div class="col-md-3">
        <button class="btn btn-warning" ng-disabled="{{isWaiting}}">Report</button>
    </div>

Output HTML produced before ajax load completed

<button class="btn btn-warning" ng-disabled="true" disabled="disabled">Report</button>

And after ajax load completed

<button class="btn btn-warning" ng-disabled="false" disabled="disabled">Report</button>

And button is still disabled. I am not sure why is this happening, I have seen couple of questions here answered to do this only.

Thanks in advance.

I am using bootstrap.js along with angular js, my code is following-

//few lines from controller
$scope.isWaiting = true;
$scope.promise = $http.get("voluumHandler.php?q=campaigns&filter=traffic-source&filterVal=" + traffic + "&from=" + from + "&to=" + to + "&tz=" + tz).success(function(response){        
        $scope.campaigns = response.rows;
        console.log(response.rows);
        $scope.isWaiting = false;
    }).error(function(response){
        alert(response);
        $scope.isWaiting = false;
    });

Here isWaiting is used for disabling and enabling the button.

<!--HTML -->
<div class="col-md-3">
        <button class="btn btn-warning" ng-disabled="{{isWaiting}}">Report</button>
    </div>

Output HTML produced before ajax load completed

<button class="btn btn-warning" ng-disabled="true" disabled="disabled">Report</button>

And after ajax load completed

<button class="btn btn-warning" ng-disabled="false" disabled="disabled">Report</button>

And button is still disabled. I am not sure why is this happening, I have seen couple of questions here answered to do this only.

Thanks in advance.

Share Improve this question asked May 30, 2015 at 1:51 codeomnitrixcodeomnitrix 4,24919 gold badges68 silver badges103 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

If you are using ng-disabled an expression must be used that returns a truthy value. An example of an expression is isWaiting. {{isWaiting}}will instead output an expression. So instead use ng-disabled="isWaiting".

<button class="btn btn-warning" ng-disabled="isWaiting">Report</button>

ngDisabled documentation

Expressions documentation

You need to give an expression to ng-disabled, instead you are giving a string("true"/"false") which is always truthy and button is always disabled.

isWaiting --> expression

{{isWaiting}} --> value of expression

In your case:

ng-disabled="isWaiting"
发布评论

评论列表(0)

  1. 暂无评论