jpkleemans / angular-validate

Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
MIT License
68 stars 33 forks source link

$validatorProvider is not working for me #13

Closed gchokeen closed 7 years ago

gchokeen commented 7 years ago

I configured the global validation settings as below in app.js and I am loading the controller using loadplugin. Global configuration is not picking up in this case.

Note: Inline configuration of options works

app.config(function ($stateProvider, $urlRouterProvider,$validatorProvider){
         $validatorProvider.setDefaults({
            errorElement: 'small',
            errorClass: 'help-block',
        });

        $stateProvider
            .state ('admin', {
                url: '/admin',
                templateUrl: 'views/admin.html',
                controller: 'adminCtrl',
                resolve: {
                    loadPlugin: function($ocLazyLoad) {
                        return $ocLazyLoad.load ([
                            {
                                name: 'vendors',
                                files: [
                                    'vendors/bower_components/autosize/dist/autosize.min.js',
                                    'vendors/bower_components/jquery-validation/dist/jquery.validate.min.js',
                                    'vendors/bower_components/jpkleemans-angular-validate/dist/angular-validate.min.js',

                                    'js/controllers/adminCtrl.js'
                                ]
                            }
                        ])
                    }
                }                
            });

})
jpkleemans commented 7 years ago

Hi, $validatorProvider is only available when angular-validate.min.js is loaded. Because you use lazy loading, the dependency resolver of Angular doesn't know how to inject $validatorProvider into your config function.

gchokeen commented 7 years ago

I got your point!

I also loading the angular-validate.min.js in index.html. I know lazy loading overriding the config. Is there anyway you can think off to make it work with lazy load. because I am using lazy load all over the project :(

jpkleemans commented 7 years ago

If you already load angular-validate.min.js and jquery.validate.min.js in your index, there's no need to load it again with lazy loading.

gchokeen commented 7 years ago

Oh Yes, I removed it and it works well thanks