import { Component , OnInit } from '@angular/core' ; import { PostsService } from './posts.service' ; @ Component ( { selector : 'app-posts' , templateUrl : './posts.component.html' , styleUrls : [ './posts.component.css' ] } ) export class PostsComponent implements OnInit { posts = [ ] ; errorMessage : any ; constructor ( private postsService ) { } ngOnInit ( ) { this . postsService . getAllPosts ( ) . subscribe ( posts => { this . posts = posts ; } , error => { this . errorMessage = error ; } ) ; } }