Skip to content

Instantly share code, notes, and snippets.

@NishuGoel
Created January 7, 2019 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishuGoel/48a0ca4e3a098cc63afa2e334b3c34ae to your computer and use it in GitHub Desktop.
Save NishuGoel/48a0ca4e3a098cc63afa2e334b3c34ae to your computer and use it in GitHub Desktop.
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