ng-disabled不使用引导按钮

cod*_*rix 6 javascript ajax twitter-bootstrap angularjs

我正在使用bootstrap.js和角度js,我的代码如下 -

//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;
    });
Run Code Online (Sandbox Code Playgroud)

这里isWaiting用于禁用和启用按钮.

<!--HTML -->
<div class="col-md-3">
        <button class="btn btn-warning" ng-disabled="{{isWaiting}}">Report</button>
    </div>
Run Code Online (Sandbox Code Playgroud)

在ajax加载完成之前生成的输出HTML

<button class="btn btn-warning" ng-disabled="true" disabled="disabled">Report</button>
Run Code Online (Sandbox Code Playgroud)

并在ajax加载完成后

<button class="btn btn-warning" ng-disabled="false" disabled="disabled">Report</button>
Run Code Online (Sandbox Code Playgroud)

并且按钮仍然被禁用.我不确定为什么会发生这种情况,我已经看到这里的几个问题只能回答这个问题.

提前致谢.

Way*_*ery 11

如果您正在使用ng-disabled表达式,则必须使用返回truthy值的表达式.表达的一个例子是isWaiting.{{isWaiting}}将输出一个表达式.所以改为使用ng-disabled="isWaiting".

<button class="btn btn-warning" ng-disabled="isWaiting">Report</button>
Run Code Online (Sandbox Code Playgroud)

ngDisabled文档

表达式文档


小智 7

你需要给一个表达式ng-disabled,而不是你给一个字符串("真" /"假"),这始终是truthy和按钮总是被禁用.

isWaiting - >表达

{{isWaiting}} - >表达的价值

在你的情况下:

ng-disabled="isWaiting"
Run Code Online (Sandbox Code Playgroud)