import { Component, OnInit } from '@angular/core'; import { DataloaderService } from 'app/services/dataloader.service'; import { Post } from '../../model/post'; import { Observable } from 'rxjs/Observable'; @Component({ selector: 'app-posts', templateUrl: './posts.component.html', styleUrls: ['./posts.component.css'] }) export class PostsComponent implements OnInit { posts:Observable; constructor(private dataloaderService:DataloaderService) { } ngOnInit() { //fetch the posts this.posts = this.dataloaderService.getPosts(); } }