Using ng-repeat and ng-class on rows inside a table

假如想象 提交于 2019-11-28 06:40:43

This should actually work fine. Person should be available on the tr element as well as on its children since they share the same scope.

This seems to work fine for me:

<table>
    <tr ng-repeat="person in people" ng-class="rowClass(person)">
        <td>{{ person.name }}</td>
    </tr>
</table>

http://jsfiddle.net/xEyJZ/

Actually, you can use "person" in the context you are referring to. It exists on the item being repeated as well as any items within it. The reason is that any directives on a particular element share the same $scope object. ng-repeat has a Priority of 1000, so it has already created its $scope and put "person" into it, therefore "person" is available to ng-class.

See this Plnkr:

http://plnkr.co/edit/ZI5Pv24U01S9dNoDulh6

Normally I like to give a more comprehensive answer but there is too much code involved in this bit to do that. So will just show what is most important and hope anyone looking at this knows how use it. My dynamic JSON array has both columns and rows in it but the main thing that matters for this bit is ng-show="$last". This should only show the last row in the dynamic JSON array.

<tr ng-repeat="row in table.rows" ng-show="$last">

   <td ng-repeat="column in table.cols" ng-show="column.visible == true" nowrap >{{row[column.columnname]}}</td>
</tr>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!