Let's carry out the following steps to create an asynchronous blog post service:
- First, we will import our new service into our PostsModule so that it can be injected into any components in the module that need to use the service. We should also add our routes for our new PostListComponent so that it is the default child component in the router-outlet when navigating to /posts:
...import { BlogPostsService } from "./blog-posts.service";import { PostListComponent } from './post-list/post-list.component';const ROUTES = [{ path: "posts", component: PostsComponent, children: [ { path: "", component: PostListComponent }, { path: ":id", component: PostComponent } ]}];@NgModule({ imports: [ ... RouterModule.forChild(ROUTES) ], ...