I'm trying to build a simple search function for my web app. there is documentation on how to create it with real time database.
What changes do I need to make to make this work on firestore ?
this tutorial was taken from here https://angularfirebase.com/lessons/autocomplete-search-with-angular4-and-firebase/
it has a nice video as well :)
this is how to make it with real time database:
#movies.service.ts
import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from '
angularfire2/database';
@Injectable()
export class MoviesService {
constructor(private db: AngularFireDatabase) { }
getMovies(start, end): FirebaseListObservable<any> {
return this.db.list('/movies', {
query: {
orderByChild: 'Title',
limitToFirst: 10,
startAt: start,
endAt: end
}
});
}
}
The Autocomplete Search Component
<h1>Movie Search</h1>
<input type="text" (keydown)="search($event)" placeholder="search
movies..." class="input">
<div *ngFor="let movie of movies">
<h4>{{movie?.Title}}</h4>
<p>
{{movie?.Plot}}
</p>
</div>
<div *ngIf="movies?.length < 1">
<hr>
<p>
No results found :(
</p>
</div>
TS
import { Component, OnInit } from '@angular/core';
import { MoviesService } from '../movies.service';
import { Subject } from 'rxjs/Subject'
@Component({
selector: 'movie-search',
templateUrl: './movie-search.component.html',
styleUrls: ['./movie-search.component.scss']
})
export class MovieSearchComponent implements OnInit {
movies;
startAt = new Subject()
endAt = new Subject()
constructor(private moviesSvc: MoviesService) { }
ngOnInit() {
this.moviesSvc.getMovies(this.startAt, this.endAt)
.subscribe(movies => this.movies = movies)
}
search($event) {
let q = $event.target.value
this.startAt.next(q)
this.endAt.next(q+"\uf8ff")
}
}