我遇到了让radiogroup字段在ng-repeat中工作的问题。
我有一组重复的表单字段:
$scope.repeatables = {
REPEATGRP: [
{data:{text1: "test 1", radio1: 1}},
{data:{text1: "test 2", radio1: 0}}
]
};
表单数据是这样启动的,有两组字段:
Matrix3d rotation_matrix(Vector3d vector0, Vector3d vector1)
{
vector0.normalize();
vector1.normalize();
// vector orthogonal to both inputs
Vector3d u = vector0.cross(vector1);
if (!u.norm())
{
if (vector0 == vector1)
return Matrix3d::Identity();
// return rotation matrix that represents 180 degree rotation
Matrix3d m1;
m1 << -1, 0, 0,
0,-1, 0,
0, 0, 1;
return m1;
}
/* For the angle between both inputs:
* 1) The sine is the magnitude of their cross product.
* 2) The cosine equals their dot product.
*/
// sine must be calculated using original cross product
double sine = u.norm();
double cosine = vector0.dot(vector1);
u.normalize();
double ux = u[0];
double uy = u[1];
double uz = u[2];
Matrix3d cross_product_matrix;
cross_product_matrix << 0, -uz, uy,
uz, 0,-ux,
-uy, ux, 0;
Matrix3d part1 = Matrix3d::Identity();
Matrix3d part2 = cross_product_matrix * sine;
Matrix3d part3 = cross_product_matrix*cross_product_matrix * (1 - cosine);
return part1 + part2 + part3;
}
但是这两个广播组的行为表现得彼此相关。这很难描述,但你可以在这里看到它:http://plnkr.co/edit/y4pCt0IsDTD8BzeA8SWZ?p=preview
答案 0 :(得分:1)
只需在您的可重复项中添加一个属性名称,然后将其设置在单选按钮中。
正在发生的事情是,由于它们都具有相同的名称,因此浏览器将它们分组为好像它们只是一组单选按钮:
(我也改变了id,所以你没有重复相同的id。)
HTML:
<label for="radio1_1" class="radio-inline">
<input ng-required="true" name="{{rpt.name}}" type="radio" ng-model="rpt.data.radio1" id="{{rpt.name}}_1" value="1" /> Yes
</label>
<label for="radio1_2" class="radio-inline">
<input ng-required="true" name="{{rpt.name}}" type="radio" ng-model="rpt.data.radio1" id="{{rpt.name}}_2" value="0" /> No
</label>
SCOPE
$scope.repeatables = {
REPEATGRP: [
{data:{text1: "test 1", radio1: 1,name:'r1'}},
{data:{text1: "test 2", radio1: 0,name:'r2'}}
]
};
答案 1 :(得分:1)
一个不要改变对象的解决方案,只需将作为ng-repeat一部分的$ index变量添加到输入的名称中。
<input ng-required="true" name="radio1-{{$index}}" type="radio" ng-model="rpt.data.radio1" id="radio1_1" value="1" /> Yes
根据你的Plunker,这里有效: