I understand a declarable:
declarations
arrayBut what actually is a declarable? A service class sort of belongs to a module, so why is a service class not a declarable? Or, more generally, what does it mean to declare something inside a module?
Declarables allow the angular compiler to know which module will actually contain the component, directive or pipe.
As the compiler generates the factories that make the views, it will integrate those components with the module they were declared, and only refer to them in any other module that might be using them.
This is why you only want each component, pipe and directive to only be declared in a maximum of one module.
Services are put together with the rest and referenced as needed by other tools such as webpack or in some cases indirectly by the browser. The angular compiler does not need to compile the service code, it just uses them as normal javascript code.
Edit: Specify that services don't need to be compiled by the angular compiler. Of course if it's typescript it will still be compiled but by the typescript compiler not the angular one.
declarations
makes selectors and pipe names known to Angular.
When it compiles a components template, it looks up matching components, directives and pipes in declarations of the current module and imported modules, for them to be applied to the elements where selectors and pipe names match.
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