ng-switch
在使用嵌套的“ng-repeat”和指令根据提供的列定义和行数据(2 个不同的 JSON 对象)呈现表时出现错误:
有什么方法可以使用“ng-repeat”并ng-switch
在不使用包装元素的情况下渲染表格单元格。
Error: [$compile:ctreq] Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found!
这是我的表格模板
<table id={{metaData.id}} name="{{metaData.name}}" class="{{metaData.classes}}">
<tbody>
<tr ng-repeat="record in data">
<td ng-repeat="col in metaData.columns" ng-switch on="col.type"
ng-switch-when="index"> {{record.$index + 1}} </td>
</tr>
</tbody>
我暂时做的工作
我正在使用以下方式动态渲染ng-if
表格:cell
rows
<table id={{metaData.id}} name="{{metaData.name}}" class="{{metaData.classes}} vk-table" >
<tbody>
<tr ng-repeat="record in data | orderBy : sortBy : reverse">
<td ng-repeat-start="col in metaData.columns" ng-if="col.type == 'index'"> {{$parent.$parent.$index + 1}}. </td>
<td ng-if="col.type =='name'">{{record.name = [record.fname, record.mname, record.lname].join(' ') }}</td>
<td ng-if="col.type =='date'">{{record[col.dataKey] = toDate(record[col.dataKey]) | date : 'mediumDate'}}</td>
<td ng-if="col.type =='inMobile'">
<a href="tel:{{record[col.dataKey]}}">{{record[col.dataKey]}}</a>
</td>
<td ng-if="col.type =='email'">
<a href="mailto:{{record[col.dataKey]}}">{{record[col.dataKey]}}</a>
</td>
<td ng-if="col.type =='gender'">{{record[col.dataKey] == 'm' ? 'Male' : 'Female'}}</td>
<td ng-if="col.type =='place'">{{record[col.dataKey].name}}</td>
<td ng-repeat-end ng-if="!col.type">{{record[col.dataKey]}}</td>
</tr>
</tbody>
</table>
如何在ng-switch
不使用其他元素的情况下实现相同的输出?