I am trying to get a way to call a function inside my component only after loading, as long as the component is loaded, several times my function is called and I do not want this, here is my code:
<div class="form-group" [ngClass]="aplicaCssErro('name')">
<label>
NAME
</label>
<input class="form-control" type="text" formControlName="name" autocomplete="off">
</div>
My function:
verificaValidTouched(campo){
return !this.formulario_cadastro.get(campo).valid && this.formulario_cadastro.get(campo).touched;
}
aplicaCssErro(campo){
console.log(this.verificaValidTouched(campo));
return{
'has-error': this.verificaValidTouched(campo),
'has-feedback': this.verificaValidTouched(campo)
}
}
The functions only serve to add a validation class in my data-driven form. What I want, is to just call those functions that are in my HTML after I've loaded the page or something better than this, because when loading the page the functions are called several times. Can anyone tell me a solution?
Subjectstake a look at subjects and observables