Angular Dir-Pagination 和调用控制器函数
Angular Dir-Pagination and calling controller function
我在 table 下面有一个 angular html 片段 我正在尝试使用 Dir-Paginate 进行连接并且还更改了 table 行class 基于 controller.js
上的函数
<tr dir-pagination="response in vm.responses | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage" class="{{ vm.getRowClass($index) }}">
<td> {{ $index + 1 }}</td>
<td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
<td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
<tr>
<dir-pagination-controls ng-show="appvm.showDataTable()" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="ng/pagination"></dir-pagination-controls>
如果我删除所有 Dir-Pagination 语法并使其成为普通的 ng-repeat
,vm.getRowClass($index)
将正常工作,根据函数的逻辑更改 class。但是,当我尝试添加目录分页语法时,出现 $Index is undefined
错误。
问题似乎是 Dir-Paginate 不允许我传入 $index
或与 <tr>
在同一行的任何项目
在评论和一些尝试之后我找到了解决方案。
我需要将 track by $index
添加到 itemsPerPage: $root.pagination.itemsPerPage
区域的末尾。
下方正确显示。
<tr dir-pagination="response in vm.responses | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage track by $index" class="{{ vm.getRowClass($index) }}">
<td> {{ $index + 1 }}</td>
<td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
<td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
<tr>
我在 table 下面有一个 angular html 片段 我正在尝试使用 Dir-Paginate 进行连接并且还更改了 table 行class 基于 controller.js
上的函数<tr dir-pagination="response in vm.responses | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage" class="{{ vm.getRowClass($index) }}">
<td> {{ $index + 1 }}</td>
<td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
<td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
<tr>
<dir-pagination-controls ng-show="appvm.showDataTable()" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="ng/pagination"></dir-pagination-controls>
如果我删除所有 Dir-Pagination 语法并使其成为普通的 ng-repeat
,vm.getRowClass($index)
将正常工作,根据函数的逻辑更改 class。但是,当我尝试添加目录分页语法时,出现 $Index is undefined
错误。
问题似乎是 Dir-Paginate 不允许我传入 $index
或与 <tr>
在评论和一些尝试之后我找到了解决方案。
我需要将 track by $index
添加到 itemsPerPage: $root.pagination.itemsPerPage
区域的末尾。
下方正确显示。
<tr dir-pagination="response in vm.responses | toArray | orderBy:'-completionTime' | itemsPerPage: $root.pagination.itemsPerPage track by $index" class="{{ vm.getRowClass($index) }}">
<td> {{ $index + 1 }}</td>
<td><a ui-sref="response({uri:response.uri})">{{ response.name }}</a></td>
<td><a href="mailto:{{ response.email }}">{{ response.email }}</a></td>
<tr>