Show and hide div after filter with AngularJS

0

Hello.

I have the following filter:

<div ng-repeat="user in users|filter:search| filter:selectedCategories| filter:selectedType| filter:selectedDate| orderBy:'+id':true| limitTo: 10">

You want to put the text "Last users" when the page loads and I want it to not appear when the user uses the filter.

Any ideas?

edit:

<div ng-app="testeApp">
      <script>
            var myApp = angular.module('testeApp',[]);
            myApp.controller('testeController', function($scope){
                  $scope.users=[
                        {id:1, name:"Fulano", startdate:'janeiro', categories:'normal', type:'xpto'},
                  ];
            });
      </script>
</div>


<form>
  <input type="text" ng-model="search" class="text-input" placeholder="Nome, Cidade, País, Continente" autofocus />
<select ng-model="selectedCategories">
    <option value="">-- Categoria --</option>
    <option value='normal'>Normal</option>
</select>
  <select class="type" ng-model="selectedType">
    <option value="">-- Tipo --</option>
    <option value='xpto'>xpto</option>
</select>

  <select class="data" ng-model="selectedDate">
    <option value="">-- Data --</option>
    <option value="janeiro">janeiro</option>
    <option value="fevereiro">fevereiro</option>
  </select>
</form>

<h3 ng-if="!search">Últimos usuários adicionados</h3>
    
asked by anonymous 17.01.2017 / 16:21

1 answer

1

Use an alias for the result of your filter chain:

<div ng-repeat="user in users|filter:search|filter:selectedCategories as filteredUsers">

Angular copies the final value of the filtered collection to $scope . You can then compare the original with the ending:

<span ng-if="users.length == filteredUsers.length">Últimos usuários</span>
    
18.01.2017 / 16:46