Remove mandatory input with angular

0

I have a question with angularjs, I am doing a registration form, and have a certain form that I am doing a validation and has an option to insert several phones, it inserts the phones clears the input data and goes to a list with angular repeat.

My question is, when I enter at least 1 phone, it will remove the required field, or set the field as valid.

I've tried using $setValidity(); but was not that what I'm doing wrong?

Excerpt from the code I'm using

var $formElem,$formScope;
$formElem = angular.element(formCliente);
$formScope = $formElem.scope();
$formScope.formCliente.telefone.$setValidity('required', false);
    
asked by anonymous 11.03.2017 / 17:20

1 answer

0

You can use ng-required , which takes an expression and adds or does not require it according to the result of its variable.

<input type="number" data-ng-model="telefoneInput" ng-required="temAlgumTelefoneNaLista"/> 

where your $scope.temAlgumTelefoneNaLista = (suaListaDeTelefones.length > 0);

    
12.03.2017 / 00:25