Angular filter html

Asked

Viewed 257 times

2

I have an ng-repeat that returns me a list.

Every line, I have a default text that arises if a variable is > 0

So far everything is working.

How do I add to filter only show the record when the default text is filled?

The contents are in a div:

<div name="pesq" id "pesq" style="padding-left: 5px;color:red"> =texto padrão= </div>


<tr ng-repeat="nome in nomes | filter: 'pesq'">
  • Lucas, it would basically show in the list only the records that have the text of the div

2 answers

3

Can do:

<tr ng-repeat="[objecto] in [colecção] | filter: {[propriedade]: '[texto]'}">

Where propriedade is the name of the property of the object you want to filter, and texto is the text you want to find in the property.

That is, (assuming the name of the property is pesq and the text is padrao):

<tr ng-repeat="nome in nomes | filter: {pesq: 'padrao'}">

All objects nome containing the property pesq with the text padrao will be written in the DOM.

0

Dude, an option would be to do this only with css and jquery. You can leave by default the text hidden with display:none or leaving him invisible with visibility:hidden, ai in its condition, you would only capture the element with jquery and add css. Example $('#elemento').css("display","block"); or $('#elemento').css("visibility",visible"); If you have any questions, comment on :D

$('#inp').focusout(function(){
   if($(this).val().length >0)
   {
     $('#texto').css('display','block')
   }
   else{
     alert('tamanho menor que 0')
     $('#texto').css('display','none')
   }

})
#texto{
  display: none;
}
<p id='texto' > texto exibido </p>

<input type="text" id="inp"/>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script>

  • thanks for the tip, maybe it’s a way... have some example?

  • @user103907 edited the answer, test there! Type a text and click off the input, then click the input and click off it without typing anything.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.