2015-06-25 189 views
-1

我想設置基於下拉選擇的單選按鈕值,讓我們假設我有三個值在下拉(A,B和C),如果A或B被選中我想設置單選按鈕默認值爲摘要如果選擇C,我希望設置值爲Detailed。另外當A & B被選中時,我想讓它不可編輯。 請幫助這是我第一次使用無線電與AngularJS。如何根據下拉選擇設置單選按鈕值?

main.html中

<div class="row"> 
    <div class="form-group col-md-6 fieldHeight"> 
     <label for="cycleName" class="col-md-6 required">Scope Type :</label> 
     <div class="col-md-6"> 
      <select kendo-drop-down-list k-data-text-field="'text'" 
       k-option-label="'Select'" k-data-value-field="'id'" 
       k-data-source="assessmentTypeOptions" name="assessmentType" 
       required ng-model="riskAssessmentDTO.scopeType" id="assessmentType" 
       maxlength="256" ng-change="assessmentType()"></select> 
       <p class="text-danger" 
        ng-show="addAssessment.assessmentType.$touched && addAssessment.assessmentType.$error.required">Assessment 
        Type is required</p> 
     </div> 
    </div> 
    <div class="form-group col-md-6 fieldHeight"> 
     <label for="assessmentType" class="col-md-5 required">Assessment Type :</label> 
     <label class="radio-inline"><input type="radio" 
      name="summary" id="summary" ng-value="'summary'" 
      ng-model="riskAssessmentDTO.erhFlag" ng-disabled="disableAssessmentType" >Summary </label> 
     <label class="radio-inline"><input type="radio" 
      name="detail" id="detail" ng-value="'N'" 
      ng-model="riskAssessmentDTO.erhFlag" ng-disabled="disableAssessmentType">Detailed</label> 
     <p class="text-danger" 
      ng-show="addAssessment.includeERHFlag.$touched && addAssessment.includeERHFlag.$error.required">Assessment 
      Name is required</p> 
    </div> 
</div> 

main.js

$scope.assessmentType = function() { 
         $scope.riskAssessmentDTO.assessmentName = ''; 
         $scope.riskAssessmentDTO.erhFlag = 'Y'; 

         $scope.showRefineERH = false; 
         if ($scope.riskAssessmentDTO.scopeType === 'RA_GEO_LOCAT') { 
          $scope.disableAssessmentType = true; 
          $scope.riskAssessmentDTO.erhFlag = 'summary'; 
         } else if ($scope.riskAssessmentDTO.scopeType === 'RA_LEGAL_ENTITY') { 
          $scope.disableAssessmentType = true; 
          $scope.riskAssessmentDTO.erhFlag = 'summary'; 
         } else if ($scope.riskAssessmentDTO.scopeType === 'RA_BUS_UNIT') { 
          $scope.disableAssessmentType = false; 
          $scope.riskAssessmentDTO.erhFlag = 'detailed'; 
         } 
        }; 
+0

「另外,當A和B被選中時,我想讓它不可編輯。」你想要做什麼不可編輯? –

+0

單選按鈕,用戶應該無法在無線電上做出選擇,應該禁用它。 – aftab

+0

這是你的整個js文件嗎?您是否定義了角度模塊或控制器? –

回答

1

使用NG-禁用的單選按鈕和使用範圍變量$ scope.selectedIndex將其設置爲虛假或真實

<input type="radio" ng-disabled="selectedInderx==0"> 

並通過從html中傳遞$ index在select中的ng-change函數中設置$ scope.selectedIndex

+0

我改變了一些代碼的問題ng-disabled正在基於下拉值現在我想改變單選按鈕值..我怎麼能做到這一點與上述條件? – aftab

+0

只是設置單選按鈕的Ng模型的值 – CognitiveDesire

+0

我已經編輯了我的Js問題請看看它是我正確實施的東西。 – aftab

相關問題