开发者社区> 问答> 正文

使用angular查询来自firestore的动态输入的实时数据

到目前为止,我已经尝试了这个,我能够获取所有数据,但我只想要与用户选择的输入相对应的数据。我是新手,有任何建议。

component.html: -

Name: <select [(ngModel)] = "selectedLevel" (change)="selected()"> <option *ngFor="let post of posts | async" [ngValue]="post">{{post.user}}

Component.ts: -

export interface Post{ user: string; callType : string; callDuration: string; callTime : string; }

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] })

export class AppComponent { constructor (private afs:AngularFirestore){ } public CallDetails: object = []; public calls =[];

postsCol: AngularFirestoreCollection posts: Observable<Post[]>

selectedLevel; ngOnInit(){

this.postsCol = this.afs.collection<Post>('acb', ref => ref.orderBy('user', 'asc'));
this.posts = this.postsCol.snapshotChanges().map(actions => {
  return actions.map(a => {
    const data = a.payload.doc.data() as Post;
    const id = a.payload.doc.id;
    return { id, ...data };
  })
})
 return this.posts;

}

这是我想要的输出格式

展开
收起
被纵养的懒猫 2019-09-20 20:18:51 708 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Angular从零到一 立即下载
《Pulsar 2.8.0 功能特性概述及规划》 立即下载
低代码开发师(初级)实战教程 立即下载