I am just starting to learn Angular. I have come across several examples using ngModule
decorators over an empty class
.
What I want to know is... Is the class
declared directly below the ngModule
decorator only used to initialize a module or does it serve any other purpose?
link. Declarables are the class types —components, directives, and pipes— that you can add to a module's declarations list. They're the only classes that you can add to declarations .
An NgModule is a class marked by the @NgModule decorator. @NgModule takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.
The @NgModule() decorator is a function that takes a single metadata object, whose properties describe the module. The most important properties are as follows. declarations: The components, directives, and pipes that belong to this NgModule.
You can for example use the constructor or implement ngDoBootstrap
to execute code when a lazy loaded module was loaded the first time (initialized)
You can also inject services to the constructor so that they are instantiated by DI when the application or the lazy loaded module is initialized.
I can't remember seeing other examples.
Besides that it only carries the @NgModule()
decorator and the information provided there.
(There might be some additional code generated when the app is built)
See also the ngDoBootstrap
comment in https://angular.io/guide/entry-components
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