import { PostService } from './../../../components/services/post.service';
import { PostsDB } from './../../../components/model/posts';
import { NotificationService } from './../../../components/services/toastr.service';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-articles',
templateUrl: './articles.component.html',
styleUrls: ['./articles.component.css']
})
export class ArticlesComponent implements OnInit {
articleList: PostsDB[];
constructor(private postService: PostService,
private toastService: NotificationService,//for notifications
) { }
ngOnInit() {
this.getAllPosts();
}
getAllPosts() {
const x = this.postService.getPosts();
x.snapshotChanges().subscribe(
(posts) => {
this.articleList = [];
posts.forEach((element) => {
const y = element.payload.toJSON();
y['$key'] = element.key;
this.articleList.push(y as PostsDB);
});
},
(err) => {
this.toastService.showSuccess("Error", "error occurred"); }
);
}
}
我正在Angular Firebase Realtime DB中构建具有多个帖子类型的博客应用。我只想像我们在SQL中那样实现Firebase查询,例如SELECT * FROM POSTTABLE WHERE POSTCATEGORY ='ARTICLE'。 如何在Firebase Realtime数据库中实现此类查询。
这是我的Component.ts代码,从Firebase数据库中获取所有帖子:- Appcomponent.component.ts