Created
January 7, 2019 21:41
-
-
Save NishuGoel/48a0ca4e3a098cc63afa2e334b3c34ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {Subject} from 'rxjs/Subject'; | |
import {Observable} from 'Rxjs/Rx'; | |
import { AngularFirestore } from 'angularfire2/firestore'; | |
@Component({ | |
selector: 'app-root', | |
templateUrls:'' | |
}) | |
export class AppComponent implements OnInit { | |
searchterm: string; | |
startAt = new Subject(); | |
endAt = new Subject(); | |
startObs = this.startAt.asObservable(); | |
endObs = this.endAt.asObservable(); | |
names; | |
public data: Observable<any[]>; | |
constructor(private db: AngularFirestore) { | |
// this.data = db.collection('/data').valueChanges(); | |
} | |
ngOnInit(){ | |
Observable.combineLatest(this.startObs, this.endObs).subscribe((value) => { | |
this.firequery(value[0], value[1]).subscribe((names) => {this.names = names; | |
}) | |
}) | |
} | |
search($event){ | |
let q = $event.target.value; | |
this.startAt.next(q); | |
this.endAt.next(q + "\uf8ff"); | |
} | |
firequery(start, end){ | |
return this.db.collection('data', ref => ref.limit(4).orderBy('name').startAt(start).endAt(end)).valueChanges(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment