import { Component, OnInit } from '@angular/core'; import { DataloaderService } from 'app/services/dataloader.service'; import { Post } from '../../model/post'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/merge'; import 'rxjs/add/operator/concatMap'; import 'rxjs/add/observable/from'; import 'rxjs/add/operator/distinct'; @Component({ selector: 'app-posts', templateUrl: './posts.component.html', styleUrls: ['./posts.component.css'] }) export class PostsComponent implements OnInit { postTypes: Observable; posts:Observable; constructor(private dataloaderService:DataloaderService) { } ngOnInit() { //fetch the posts this.posts = this.dataloaderService.getPosts(); this.postTypes = this.getPostTypes(); this.postTypes.subscribe(test=>{ console.log('result of subscribe: '+test); }); } getPostTypes():Observable { return this.posts.map(posts=>{ let result = new Set(); for(let post of posts) { result.add(post.type); } console.log('got these post types!'); console.log(result); return Array.from(result); }); } filterOnType(type:String): void { } }