homepage/src/app/components/posts/posts.component.ts
2018-03-04 14:46:53 +01:00

49 lines
1.2 KiB
TypeScript

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<String[]>;
posts:Observable<Post[]>;
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<String[]> {
return this.posts.map(posts=>{
let result = new Set<String>();
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 {
}
}