netceteragroup / valdr

A model centric approach to AngularJS form validation
http://netceteragroup.github.io/valdr/
MIT License
153 stars 43 forks source link

For what `addValidator` step has been provided? #94

Closed vskosp closed 9 years ago

vskosp commented 9 years ago

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!

philippd commented 9 years ago

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');
vskosp commented 9 years ago

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