Book Image

Beginning Server-Side Application Development with Angular

By : Bram Borggreve
Book Image

Beginning Server-Side Application Development with Angular

By: Bram Borggreve

Overview of this book

Equip yourself with the skills required to create modern, progressive web applications that load quickly and efficiently. This fast-paced guide to server-side Angular leads you through an example application that uses Angular Universal to render application pages on the server, rather than the client. You'll learn how to serve your users views that load instantly, while reaping all the SEO benefits of improved page indexing. With differences of just 200 milliseconds in performance having a measurable impact on your users, it's more important than ever to get server-side right.
Table of Contents (10 chapters)

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:

  1. Open your terminal and navigate to the project directory.

  2. 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...