Listing posts in the home component

The home component that we are mounting on the home page is expected to show a list of posts. Therefore, it needs to interact with the blog service to do so. Update the class to the following:

import { Component, OnInit } from '@angular/core';import { BlogService } from './../blog.service';@Component({  selector: 'app-home',  templateUrl: './home.component.html',  styleUrls: ['./home.component.css']})export class HomeComponent implements OnInit {    public posts;  constructor(    private blogService: BlogService  ) { }  ngOnInit() {    this.posts = this.blogService.getPosts();  }}

The component depends on the BlogService class, which is resolved in the constructor. The blogService instance is then used to get the list ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.