Hide element with angularjs

0

Hello. I have a routine that checks the elements of a form-group and adds the has-error class in form-validate. See below

var allElements = element.find("input");

for(var i = 0; i < allElements.length; i++) {
var field = angular.element(allElements[i]);
   if(field.parent().parent().hasClass('has-error')){                                              field.parent().parent().removeClass('has-error');
                                    }
                            }

AND FORM-GROUP IS SO

<div class="form-group">
    <div class="input-group plain-addon">                           
        <div class="input-group-addon"><span class="fa fa-user fa-fw"></span></div>
        <input type="text" ng-model="user.nickname" class="form-control" placeholder="Nome" name="nickname" required>
    </div>
    <span class="help-block"><span class="help-block">Campo obrigatório</span></span>
</div>

I now need to hide the Required field and only show when has-error . I'm starting angularjs now

    
asked by anonymous 20.07.2016 / 20:57

2 answers

1

You can use ng-hide to hide and ng-show to display the html or ng-if tag so that the component only exists if true

p>

More information link link

    
21.07.2016 / 15:26
1

I think with css you can solve it, you can add a class along with help-block or use it (depending on its usefulness in the application, this might not be interesting) try something type;

.help-block {
  display: none;
}
.has-error .help-block {
  display: block;
}

If you choose to create a specific class for this, just replace the help-block with it.

    
06.11.2018 / 02:10