ng-disabled不使用引导按钮

时间:2022-08-22 17:00:41

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

我正在使用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;
    });

Here isWaiting is 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.

提前致谢。

2 个解决方案

#1


9  

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

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

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

ngDisabled documentation

ngDisabled文档

Expressions documentation

表达式文档

#2


7  

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.

您需要为ng-disabled提供一个表达式,而不是给出一个字符串(“true”/“false”),它始终是真实的,并且始终禁用按钮。

isWaiting --> expression

isWaiting - >表达式

{{isWaiting}} --> value of expression

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

In your case:

在你的情况下:

ng-disabled="isWaiting"

#1


9  

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

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

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

ngDisabled documentation

ngDisabled文档

Expressions documentation

表达式文档

#2


7  

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.

您需要为ng-disabled提供一个表达式,而不是给出一个字符串(“true”/“false”),它始终是真实的,并且始终禁用按钮。

isWaiting --> expression

isWaiting - >表达式

{{isWaiting}} --> value of expression

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

In your case:

在你的情况下:

ng-disabled="isWaiting"