[英]Changing multiple radio buttons selection based upon one radio checked in angularjs
I am new to angularjs and stuck at a situation where i want to bind the selected radio option to model/controller object. 我是angularjs的新手并且遇到了我想要将所选的无线电选项绑定到模型/控制器对象的情况。 what i am trying to do is, All three radio buttons(A, B and C) should show same option which is choosen in App1 radio options, later each(A, B and C radio button options) can be changed depending on the usecase, i want to save the clicks for user.
我想要做的是,所有三个单选按钮(A,B和C)应该显示相同的选项,在App1无线电选项中选择,以后每个(A,B和C单选按钮选项)可以根据用例更改,我想保存用户的点击次数。
For example: if a user chooses Y option in App1 set of radio buttons then all the three AB and C radio button option with Y option should be checked. 例如:如果用户在App1的单选按钮组中选择Y选项,则应选中带有Y选项的所有三个AB和C单选按钮选项。
Any help is much appreciated. 任何帮助深表感谢。
Plunk here
https://plnkr.co/edit/vuLJdUFSTsUp5hfoazBp?p=preview Plunk here
https://plnkr.co/edit/vuLJdUFSTsUp5hfoazBp?p=preview
You can make use of index provided by angular. 您可以使用angular提供的索引。 Here is the code how I do
这是我的代码
html code: 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>
Controller code: 控制器代码:
$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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.