Generate and Lazy Load the PostsModule
We will generate the PostsModule
using the ng
command and lazy load the PostsModule
in the AppRoutingModule
.
Using the ng generate
command, we can generate or scaffold out all sorts of code that can be used in our Angular application.
We will use the ng generate module
command to generate our PostsModule
.
This command has one required parameter, which is the name. In our application, we will call this module posts
. A second optional parameter is passed in in order to create a separate file to hold the routes for this module, the PostsRoutingModule
:
Open your terminal and navigate to the project directory.
Run the following command from inside the project directory:
ng g m posts --routing
As you can see from the output of the command, our PostsModule
is generated in the new folder src/app/posts
:
In contrast to how we load our UiModule
by importing it into our AppModule
, we will lazy load our PostsModule
using our AppRoutingModule
.
This is an optimization of how...