如何执行在angularjs NG-禁用的检查? [英] How to perform a check on ng-disabled in angularjs?
问题描述
我使用的是 fuelUX向导并Angularjs。我想启用下一个按钮或禁用在此基础上控制器的方法:
I am using a fuelUX Wizard and Angularjs. I would like the next button to be enabled or disabled basing on this controller method:
$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)
}
};
因此,我们确实这是我decleared的按钮:
So indeed this is how I decleared the buttons:
<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-禁用绑定?
And it works fine, except when I get back from the second page to the first page: if the next button is disabled in the second page it will be this way even on the first page, unless I don't edit the form there. Is there anyway to refresh the ng-disabled binding?
推荐答案
我想AngularJS无法检查的输出canMoveForward()
已经改变与否。我发现,这样的事情更容易依靠范围的变量。你可以做这样的事情:
I guess AngularJS cannot check if the output of canMoveForward()
has changed or not. I found that for this kind of things it's easier to rely on scope variables. You could do something like this:
ng-disabled="!canMoveForward"
然后在你的控制器属性只是设置为true / false作为需要:
Then in your controller just set the property to true/false as needed:
$scope.canMoveForward = false;
这篇关于如何执行在angularjs NG-禁用的检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!