如何使用AngularJS禁用按钮?

时间:2015-03-20 18:41:58

标签: javascript html angularjs kendo-ui kendo-grid

我在PROC.CTRL中有两个函数editProcessRating函数我禁用保存按钮,直到用户回答所有问题,我有查看功能(viewProcessRating)所以在这个功能上我想禁用另存为草稿并永久保存两个按钮。 我如何使用AngularJS禁用功能来完成这项任务?

到目前为止,

代码尝试了......

HTML

<div class="spaceonBottom text-center">
    <button type="submit" class="btn btn-default" ng-click="handleCancel()">Cancel</button>
    <button type="submit" class="btn btn-default" ng-disabled="disableDraft" ng-click="savePRTDraft()" ng-show="showSaveDraftBtn">Save
        as Draft</button>
    <button type="submit" class="btn btn-primary"
        ng-disabled="disableSubmitButton" ng-click="submitClicked()">Submit</button>

</div>

KENDOGRID.JS

{
                  field: '',
                  title: 'Action',
                  width: '8em',
                  template:'<a href="" ng-click=\'viewProcessRating(this.dataItem.processRatingSessionKey)\' <span ng-if="this.dataItem.viewable" class="glyphicon glyphicon-search"></span></a>&nbsp;&nbsp;<a href="" ng-click=\'editProcessRating(this.dataItem.processRatingSessionKey)\' <span ng-if=" this.dataItem.editable "><span class="glyphicon glyphicon-pencil"></span> </span></a>'

              },

Proc.Ctrl

$scope.editProcessRating = function(prcsSessionKey) {
        var prtUrl = "/getProcessRating/"+prcsSessionKey;
        $location.path(prtUrl);
    }

    $scope.viewProcessRating = function(prcsSessionKey) {
      var prtUrl = "/getProcessRating/"+prcsSessionKey;
      $scope.disableDraft = true;
      $location.path(prtUrl);
    }

RAT.CTRL

 $scope.disableSubmitButton = true;  //the submit button is disabled until user answers all 12 questions

$scope.calculateTotal = function(value){
        var total = 0;
        var findRatingKey = {};

        $scope.questionSelected[value] = true;
        for( i=0; i< $scope.questionnaire.length; i++)
        {
            total = total + $scope.ratingQstnResult.ratingSelect[i+1];
        }
        $scope.ratingQstnResult.rtgTotalScore = total;

        //If the answer to first question is High, system recommendation should be High
        if($scope.ratingQstnResult.ratingSelect[1] === 5){
            $scope.ratingQstnResult.sysRecomm = 'High';
            findRatingKey = $filter('filter')($scope.decisionList, {text:'High'});
        }else if(total < 28 ){
            $scope.ratingQstnResult.sysRecomm = 'Low';
            findRatingKey = $filter('filter')($scope.decisionList, {text:'Low'});
        } else if((total >= 28) && (total < 40)){
            $scope.ratingQstnResult.sysRecomm = 'Moderate';
            findRatingKey = $filter('filter')($scope.decisionList, {text:'Moderate'});
        } else{
            $scope.ratingQstnResult.sysRecomm = 'High';
            findRatingKey = $filter('filter')($scope.decisionList, {text:'High'});
        };
        if((!processPromiseObj.data.prQuestionnaireDTOList) || (processPromiseObj.data.sessionStatusLookUpCode === 'RA_PRT_IN_PROG')){
            $scope.ratingQstnResult.computerGeneRatingKey = findRatingKey[0].id;
            $scope.ratingQstnResult.busDecision = findRatingKey[0].id;

            for(j=1; j<= $scope.questionnaire.length; j++ ){
                if(!$scope.questionSelected[j]){
                    //console.log('there is one not selected');
                    break;
                }
            }

            if(j > $scope.questionnaire.length){
                $scope.disableSubmitButton = false;
                $scope.showBusDecDropDown = true;
            }
        }
    };

1 个答案:

答案 0 :(得分:0)

我认为j不会超过$scope.questionnaire.length。请改用j == $scope.questionnaire.length

        if (j == $scope.questionnaire.length) {
            $scope.disableSubmitButton = false;
            $scope.showBusDecDropDown = true;
        }