K
K
Kerim Berdimyradov2016-07-13 11:12:56
Angular
Kerim Berdimyradov, 2016-07-13 11:12:56

How to add ngRequired, ngMinlength, ngMaxlength etc. in $validators dynamically?

You need to dynamically add a validator to the input (not custom, but ngRequired, ngMinlength, ngMaxlength, etc.).

<input type="text" id="firstName" name="firstName" class="form-control" required="" ng-minlength="4" ng-maxlength="20" placeholder="First name" ng-model="firstname"/>

will give such a result
26a588d9fa454a60a98b5bb7e1e72f4e.png
now the same thing needs to be achieved dynamically ...
maybe there is something like
NgModelController.addValidator('ngRequired')
???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-07-13
Protko @Fesor

easy option: https://github.com/dscheerens/angular-conditional-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question