2017-05-18 49 views
1

我是新來的angularjs和卡住的情況下,我想要綁定到模型/控制器對象選定的無線電選項。我想要做的是,所有三個單選按鈕(A,B和C)應該顯示在App1無線選項中選擇的相同選項,稍後可以根據用例更改每個選項(A,B和C單選按鈕選項) ,我想保存用戶的點擊次數。更改多個單選按鈕選擇基於一個收音機簽入angularjs

例如:如果用戶在App1單選按鈕組中選擇了Y選項,那麼應該檢查帶有Y選項的所有三個A B和C單選按鈕選項。

任何幫助,非常感謝。 Plunk herehttps://plnkr.co/edit/vuLJdUFSTsUp5hfoazBp?p=preview

+0

plunker不能正常工作,需要對這個問題更清晰 –

+0

@SrikanthB編輯問題和闖入者現在正在工作 – Praveen

回答

0

您可以利用angular提供的索引。這裏是我的代碼怎麼辦

的html代碼:

<body ng-controller="MainCtrl"> 
<p>Hello {{name}}!</p> 
<div ng-repeat="app in apps" ng-init="index1 = $index"> 
    {{app.proj}} 
    <span ng-repeat="tc in typeCodes" ng-init="index2 = $index"> 
     <input type="radio" name="app_{{index1}}" ng-model="app.selectedCode" value={{tc.key}} 
       ng-change="selectionChanged(index1, app.selectedCode)">{{tc.key}} 
    </span> 
    <div> 
     <span ng-repeat="subApp in app.subApps" ng-init="index3 = $index"> 
      {{subApp.appName}}- 
      <span ng-repeat="tc in typeCodes" ng-init="index4 = $index"> 
       <input type="radio" name="tc_{{index1}}_{{index3}}" ng-model="subApp.type" ng-value="{{tc.key}}" 
         ng-checked="subApp.type === tc.key" 
         ng-change="subAppSelection(index1, index3, tc.key)">{{tc.key}} 
      </span><br> 
     </span> 
    </div><br><br> 
</div> 

控制器代碼:

$scope.selectionChanged = function (ind, type) { 
    for (var j = 0; j < $scope.apps[ind].subApps.length; j++) { 
     $scope.apps[ind].subApps[j].type = type; 
    } 
} 

$scope.subAppSelection = function (ind1, ind2, type) { 
    $scope.apps[ind1].subApps[ind2].type = type; 
} 
+0

非常感謝你花時間在這上面,像魅力一樣工作,但爲當前流程增加了一件事。在閱讀apps對象> subApp> type屬性時,我可以爲每個subApp分配一個代碼嗎?這樣特定的單選按鈕將在頁面加載後預先填充。我已經嘗試將類型屬性的代碼更新爲Y/N/M,但只有一個單選按鈕預填充對象(App1)。更新了運動員 – Praveen