Skip to content

Instantly share code, notes, and snippets.

@HugoJBello
Created September 15, 2018 09:24
Show Gist options
  • Save HugoJBello/73fb3c5c0964f29934a2d8021efb128d to your computer and use it in GitHub Desktop.
Save HugoJBello/73fb3c5c0964f29934a2d8021efb128d to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import {AngularFirestore} from 'angularfire2/firestore';
@Component({
selector: 'app-news',
templateUrl: './news.page.html',
styleUrls: ['./news.page.scss']
})
export class NewsPage implements OnInit {
data: any;
constructor(public db: AngularFirestore, private router: Router) {}
ngOnInit() {
this.getAllPosts().subscribe((data)=>{
this.data = data;
console.log(data);
});
}
getPostEntry ( postTitle: string ): Observable<any> {
return this.db.collection<any> ( "posts" , ref => ref.where ( 'title' , '==' , postTitle ) ).valueChanges ();
}
getAllPosts (): Observable<any> {
return this.db.collection<any>( "post" ).valueChanges ();
}
onGoToNewsSinglePage(article) {
//this.newsService.currentArticle = article;
//this.router.navigate(['/news-single']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment