0

Am trying to query data from firestore through searchbar,i have names of cities already stored in firestore,,so i want to search for each city by name

my HTML

<GridLayout rows="48,*">
            <SearchBar row="0" hint="Search for Users"[(ngModel)]="searchValue" [ngModelOptions]="{standalone: true}" (textChange)="onTextChanged($event)"
                (loaded)="searchBarLoaded($event)" (clear)="onClear($event)" (submit)="onSubmit($event)"></SearchBar>
            <ListView row="1" [items]="myCities$ | async"  *ngIf="myCities$" class="list-group" (itemTap)="onSelectItem($event)">
                <ng-template let-item="item">
                    <GridLayout class="item list-group-item">
                        <Label [text]="item.name" class="list-group-item-heading"></Label>
                    </GridLayout>
                </ng-template>
            </ListView>
        </GridLayout>

component.ts

public onTextChanged(args,searchValue) {

    let value = this.searchValue.toLowerCase();

    this.firebaseService.searchUsers(value)

    }

services.ts

 searchUsers(searchValue,){

const query: firestore.Query = firebase.firestore().collection("user")
.where("name", "==",searchValue)
.where("name", "==",searchValue)


query

.get()

.then((querySnapshot: firestore.QuerySnapshot) => {

  querySnapshot.forEach(doc => {

    console.log(`Large Californian city: ${doc.id} => ${JSON.stringify(doc.data().name)}`);

  });

})

.catch(err => console.log("firestoreWhereOrderLimit failed, error: " + err));

}

jass hass
  • 23
  • 5
  • It's error from FireStore itself, you don't need order by on name field when you are using equality filter on name, which means if your searchPhrase is `San Francisco` then it's going to return only `San Francisco` and order by won't have any effect. – Manoj Apr 16 '19 at 06:17
  • #manoj ,,,your suggestion solved the problem,,,however now how can i make it to start querying once i typed the first letter of any name in the searchbar ,,,, for example i pressed the letter (M) in the searchbar i want it to return all names that start with that letter (M) – jass hass May 03 '19 at 01:44
  • NOTE: i updated my whole code up there feel free to check it out – jass hass May 03 '19 at 02:01

0 Answers0