netceteragroup/valdr

For what `addValidator` step has been provided?

Closed this issue · 2 comments

When we add custom validator, we must register it using this code:

yourApp.config(function (valdrProvider) {
  valdrProvider.addValidator('customValidator');
}

But I do not understand why have you provided this step? I think, it is possible to inject validator by its service(factory) name without prior adding it to array of validators on registration step.

Thanks!

valdr has to know which of the many services in the AngularJS universe it should use as validators. This step tells valdr to get the service with the given name (by dependency injection) and use it for validation.

It is the same mechanism $http uses to get access to its http interceptors.

$httpProvider.interceptors.push('myHttpInterceptor');

Thanks for explanation. By the way, I use your plugin for a long time and I think it`s great.