I observe from the Angular documentation, that $compileProvider has both a directive() and component() method. See:
https://docs.angularjs.org/api/ng/provider/$compileProvider
I also observe the usage of that directive in the docs https://docs.angularjs.org/api/ng/service/$compile
Search for: 'compileExample'
But I don't see any explanation of the purpose.
Questions
Q) Why does $compileProvider have a directive method? What's the purpose or benefit?
Q) How is registering a directive with the compiler different from declaring a directive on a module?
How is registering a directive with the compiler different from declaring a directive on a module?
The module loader uses the $compileProvider.directive() method to load directives:
AngularJS Module Loader Source Code
/** * @ngdoc method * @name angular.Module#directive * @module ng * @param {string|Object} name Directive name, or an object map of directives where the * keys are the names and the values are the factories. * @param {Function} directiveFactory Factory function for creating new instance of * directives. * @description * See {@link ng.$compileProvider#directive $compileProvider.directive()}. */ directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),
The difference is that the module loader is capable of decorating directives and does it before the config phase. I have not found a use case for adding directives during the config phase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With