我有以下html模板:
<div ng-app ng-controller="Ctrl">
<div class="cont">
<table>
<tr><th ng-repeat="column in columns">{{column}}</th></tr>
<tr ng-repeat="(i, row) in people">
<td ng-repeat="(j, column) in columns">
<input type="radio" name="select" ng-if="column === 'id'">
<span>{{row[column]}}</span>
</td>
</tr>
</table>
</div>
</div>
然后我定义Ctrl如下
function Ctrl($scope) {
$scope.selectedId = 'aaaaa';
$scope.columns = ['id','name', 'age'];
$scope.people=[
{
'id':'aaaaa', 'name':'rachit', 'age':11
},
{
'id':'bbbbb', 'name':'gulati', 'age':12
},
{
'id':'ccccc', 'name':'rocks', 'age': 13
}
]
}
https://jsfiddle.net/en91zuxb/
它显示了所有项目的单选输入,而我的意图是只显示第一列上的单选按钮,因为第一列是id
列... ...
看来你的angular版本是旧的,这是一个与angularjs有关的错误<1.2. 尝试升级你的angularjs版本,或者使用ng-show。
下面的代码对我有效
<input type="radio" name="select" ng-show="column == 'id' ">