Get the length of list shown by ng-Show

北战南征 提交于 2019-12-01 01:23:10

I'm a little confused on the question, but could you use:

$data.length to get the total count of your data.

The $index of the ng-repeat to get the current row/length.

You could then use both values in an ng-show.

Here is the thing, on one hand you can check DOM and see how many visible rows you have, that will answer your question, but that is really bad solution, that will make performance of your angular app worse and not really angular-ish way to do things.

Another option you have is to create your own filter and use that, in this case you will be able to tell how many items you have within the filter.

Third option which is the best in my opinion is to create another scope variable and fill it in only with filtered items, of course you will need to maintain it in sync with your main list and you can do it using $watch and $watchCollection methods of your scope

.... 
$scope.$data = [ ...]

function ativoOrPerfil(item) {
  return item.ativo == filtroAtivo && (filtroPerfil == null || item.perfil == filtroPerfil )

}

function updateFiltered() {
   $scope.$dataFiltered = $scope.$data.filter(ativoOrPerfil)
}

$scope.$watch('filtroAtivo', updateFiltered)
$scope.$watch('filtroPerfil', updateFiltered)

Although keep in mind that since you are using strict filter and then your own filter, you will need to tweak updateFiltered to include all 3 conditions you have - filter, ativo and peril

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!