gpt4 book ai didi

javascript - 如何在angularjs中对ng-disabled进行检查?

转载 作者:数据小太阳 更新时间:2023-10-29 04:29:05 25 4
gpt4 key购买 nike

我正在使用 fuelUX Wizard和 Angular 。我希望基于此 Controller 方法启用或禁用下一个按钮:

$scope.canMoveForward = function(){
switch($("#moduleWizard").wizard("selectedItem").step){
case 1:
//check if the module on the first step is valid*/
return $scope.validSelection && $scope.linkedPredicateForm.$valid;

case 2:
//check if the table is empty
return !linkingDataSource.isEmpty();

case 3:
var enab= ($scope.saveModeForm.$valid && $scope.newSourceForm.$valid) ||
($scope.saveModeForm.$valid && $scope.appendSourceForm.$valid)
}
};

所以这确实是我清除按钮的方式:

<div class="actions">
<button class="btn btn-mini btn-prev" ng-click="refresh()"> <i class="icon-arrow-left"></i>Prev</button>
<button class="btn btn-mini btn-next" data-last="Finish" id="wizard-next" ng-disabled="!canMoveForward()"
ng-click="handleStepResult()">
Next<i class="icon-arrow-right"></i></button>
</div>

它工作正常,除了当我从第二页返回到第一页时:如果第二页中的下一个按钮被禁用,即使在第一页上也会这样,除非我不编辑在那里形成。无论如何要刷新 ng-disabled 绑定(bind)?

最佳答案

我猜 AngularJS 无法检查 canMoveForward() 的输出是否已更改。我发现对于这类事情,更容易依赖范围变量。你可以这样做:

ng-disabled="!canMoveForward"

然后在您的 Controller 中根据需要将属性设置为 true/false:

$scope.canMoveForward = false;

关于javascript - 如何在angularjs中对ng-disabled进行检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17083623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com