twitter-bootstrap ng-disabled 不使用引导按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30541399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ng-disabled not working with bootstrap buttons
提问by codeomnitrix
I am using bootstrap.js along with angular js, my code is following-
我正在使用 bootstrap.js 和 angular 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;
});
Here isWaitingis used for disabling and enabling the button.
这里isWaiting用于禁用和启用按钮。
<!--HTML -->
<div class="col-md-3">
<button class="btn btn-warning" ng-disabled="{{isWaiting}}">Report</button>
</div>
Output HTML produced before ajax load completed
在 ajax 加载完成之前生成的输出 HTML
<button class="btn btn-warning" ng-disabled="true" disabled="disabled">Report</button>
And after ajax load completed
并且在ajax加载完成后
<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.
提前致谢。
回答by Wayne Ellery
If you are using ng-disabledan 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".
如果您使用ng-disabled的表达式必须使用返回真值的表达式。表达式的一个例子是isWaiting。{{isWaiting}}将改为输出一个表达式。所以改为使用ng-disabled="isWaiting".
<button class="btn btn-warning" ng-disabled="isWaiting">Report</button>
回答by RobLib
You need to give an expressionto ng-disabled, instead you are giving a string("true"/"false") which is always truthyand button is always disabled.
你需要给一个表达式来ng-disabled,而不是你给一个字符串(“真” /“假”),这始终是truthy和按钮始终禁用。
isWaiting--> expression
isWaiting--> 表达式
{{isWaiting}}--> value of expression
{{isWaiting}}--> 表达式的值
In your case:
在你的情况下:
ng-disabled="isWaiting"

