Firebase query not returning results everytime it runsHow can I get query string values in JavaScript?event.preventDefault() vs. return falseReturn multiple values in JavaScript?Why does ++[[]][+[]]+[+[]] return the string “10”?Why does parseInt(1/0, 19) return 18?Is Safari on iOS 6 caching $.ajax results?How do I return the response from an asynchronous call?Is it safe to expose Firebase apiKey to the public?Querying Firebase with Angular to get document keysWhy can't I get the alert to show?

Is `x >> pure y` equivalent to `liftM (const y) x`

How to Reset Passwords on Multiple Websites Easily?

What is paid subscription needed for in Mortal Kombat 11?

Is a stroke of luck acceptable after a series of unfavorable events?

Go Pregnant or Go Home

What is the difference between "behavior" and "behaviour"?

Customer Requests (Sometimes) Drive Me Bonkers!

System.debug(JSON.Serialize(o)) Not longer shows full string

Opposite of a diet

How does buying out courses with grant money work?

What is the opposite of 'gravitas'?

How do I find the solutions of the following equation?

How to check is there any negative term in a large list?

Detecting if an element is found inside a container

Escape a backup date in a file name

Two monoidal structures and copowering

Applicability of Single Responsibility Principle

How to write papers efficiently when English isn't my first language?

Integer addition + constant, is it a group?

Trouble understanding the speech of overseas colleagues

Why are there no referendums in the US?

Type int? vs type int

Do the temporary hit points from Reckless Abandon stack if I make multiple attacks on my turn?

when is out of tune ok?



Firebase query not returning results everytime it runs


How can I get query string values in JavaScript?event.preventDefault() vs. return falseReturn multiple values in JavaScript?Why does ++[[]][+[]]+[+[]] return the string “10”?Why does parseInt(1/0, 19) return 18?Is Safari on iOS 6 caching $.ajax results?How do I return the response from an asynchronous call?Is it safe to expose Firebase apiKey to the public?Querying Firebase with Angular to get document keysWhy can't I get the alert to show?













0















I have implemented a search function in an angular 7 app that uses Firebase. I want the user to provide a from and to values always and a date value optionally. At the moment whenever a user provides all 3 values (from, to & date) the query returns the expected result. But if only from & to values are provided, the query returns expected result sometimes and doesn't at other times. I haven't been able to find a bug in my code so I need you guys to help look at my code to see if I am doing something wrong. Here's my code



schedule.service.ts



searchSchedulesList(route: string, date) 
let now = this.formatDate(this.today);

if (date != null)
return this.afs
.collection("schedules", ref =>
ref
.where("route", "==", route)
.where("date", "==", date)
.where("date", ">=", now)
.orderBy("date", "asc")
.orderBy("time", "asc")
)
.snapshotChanges();
else
return this.afs
.collection("schedules", ref => ref.where("route", "==", route))
.snapshotChanges();




schedule.component.ts



search(route: string, date) 
this.scheduleService.searchSchedulesList(route, date).subscribe(data =>
this.schedules = data.map(e =>
return
id: e.payload.doc.id,
...e.payload.doc.data()
as Schedule;
);
);




This is the search form used to get the values from to and date



<form [formGroup]="searchForm">
<div class="row">
<div class="form-group col-3">
<select formControlName="from" id="from" class="form-control">
<option value="">From</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<select formControlName="to" id="to" class="form-control">
<option value="">To</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<input formControlName="date" type="date" class="form-control" />
</div>

<div class="col-3">
<button
class="btn btn-primary btn-sm"
(click)="
search(
searchForm.value.from + searchForm.value.to,
searchForm.value.date
)
"
>
Search
</button>

<button class="btn btn-secondary btn-sm" (click)="clear()">
Reset
</button>
</div>
</div>
</form>









share|improve this question
























  • How do you query for the from and to? Through the route parameter I guess, but how are these related?

    – Renaud Tarnec
    Mar 8 at 11:20











  • @RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

    – Mena
    Mar 8 at 11:37















0















I have implemented a search function in an angular 7 app that uses Firebase. I want the user to provide a from and to values always and a date value optionally. At the moment whenever a user provides all 3 values (from, to & date) the query returns the expected result. But if only from & to values are provided, the query returns expected result sometimes and doesn't at other times. I haven't been able to find a bug in my code so I need you guys to help look at my code to see if I am doing something wrong. Here's my code



schedule.service.ts



searchSchedulesList(route: string, date) 
let now = this.formatDate(this.today);

if (date != null)
return this.afs
.collection("schedules", ref =>
ref
.where("route", "==", route)
.where("date", "==", date)
.where("date", ">=", now)
.orderBy("date", "asc")
.orderBy("time", "asc")
)
.snapshotChanges();
else
return this.afs
.collection("schedules", ref => ref.where("route", "==", route))
.snapshotChanges();




schedule.component.ts



search(route: string, date) 
this.scheduleService.searchSchedulesList(route, date).subscribe(data =>
this.schedules = data.map(e =>
return
id: e.payload.doc.id,
...e.payload.doc.data()
as Schedule;
);
);




This is the search form used to get the values from to and date



<form [formGroup]="searchForm">
<div class="row">
<div class="form-group col-3">
<select formControlName="from" id="from" class="form-control">
<option value="">From</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<select formControlName="to" id="to" class="form-control">
<option value="">To</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<input formControlName="date" type="date" class="form-control" />
</div>

<div class="col-3">
<button
class="btn btn-primary btn-sm"
(click)="
search(
searchForm.value.from + searchForm.value.to,
searchForm.value.date
)
"
>
Search
</button>

<button class="btn btn-secondary btn-sm" (click)="clear()">
Reset
</button>
</div>
</div>
</form>









share|improve this question
























  • How do you query for the from and to? Through the route parameter I guess, but how are these related?

    – Renaud Tarnec
    Mar 8 at 11:20











  • @RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

    – Mena
    Mar 8 at 11:37













0












0








0








I have implemented a search function in an angular 7 app that uses Firebase. I want the user to provide a from and to values always and a date value optionally. At the moment whenever a user provides all 3 values (from, to & date) the query returns the expected result. But if only from & to values are provided, the query returns expected result sometimes and doesn't at other times. I haven't been able to find a bug in my code so I need you guys to help look at my code to see if I am doing something wrong. Here's my code



schedule.service.ts



searchSchedulesList(route: string, date) 
let now = this.formatDate(this.today);

if (date != null)
return this.afs
.collection("schedules", ref =>
ref
.where("route", "==", route)
.where("date", "==", date)
.where("date", ">=", now)
.orderBy("date", "asc")
.orderBy("time", "asc")
)
.snapshotChanges();
else
return this.afs
.collection("schedules", ref => ref.where("route", "==", route))
.snapshotChanges();




schedule.component.ts



search(route: string, date) 
this.scheduleService.searchSchedulesList(route, date).subscribe(data =>
this.schedules = data.map(e =>
return
id: e.payload.doc.id,
...e.payload.doc.data()
as Schedule;
);
);




This is the search form used to get the values from to and date



<form [formGroup]="searchForm">
<div class="row">
<div class="form-group col-3">
<select formControlName="from" id="from" class="form-control">
<option value="">From</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<select formControlName="to" id="to" class="form-control">
<option value="">To</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<input formControlName="date" type="date" class="form-control" />
</div>

<div class="col-3">
<button
class="btn btn-primary btn-sm"
(click)="
search(
searchForm.value.from + searchForm.value.to,
searchForm.value.date
)
"
>
Search
</button>

<button class="btn btn-secondary btn-sm" (click)="clear()">
Reset
</button>
</div>
</div>
</form>









share|improve this question
















I have implemented a search function in an angular 7 app that uses Firebase. I want the user to provide a from and to values always and a date value optionally. At the moment whenever a user provides all 3 values (from, to & date) the query returns the expected result. But if only from & to values are provided, the query returns expected result sometimes and doesn't at other times. I haven't been able to find a bug in my code so I need you guys to help look at my code to see if I am doing something wrong. Here's my code



schedule.service.ts



searchSchedulesList(route: string, date) 
let now = this.formatDate(this.today);

if (date != null)
return this.afs
.collection("schedules", ref =>
ref
.where("route", "==", route)
.where("date", "==", date)
.where("date", ">=", now)
.orderBy("date", "asc")
.orderBy("time", "asc")
)
.snapshotChanges();
else
return this.afs
.collection("schedules", ref => ref.where("route", "==", route))
.snapshotChanges();




schedule.component.ts



search(route: string, date) 
this.scheduleService.searchSchedulesList(route, date).subscribe(data =>
this.schedules = data.map(e =>
return
id: e.payload.doc.id,
...e.payload.doc.data()
as Schedule;
);
);




This is the search form used to get the values from to and date



<form [formGroup]="searchForm">
<div class="row">
<div class="form-group col-3">
<select formControlName="from" id="from" class="form-control">
<option value="">From</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<select formControlName="to" id="to" class="form-control">
<option value="">To</option>
<option
*ngFor="let destination of destinations"
value=" destination.abbreviation "
> destination.fullname </option
>
</select>
</div>

<div class="form-group col-3">
<input formControlName="date" type="date" class="form-control" />
</div>

<div class="col-3">
<button
class="btn btn-primary btn-sm"
(click)="
search(
searchForm.value.from + searchForm.value.to,
searchForm.value.date
)
"
>
Search
</button>

<button class="btn btn-secondary btn-sm" (click)="clear()">
Reset
</button>
</div>
</div>
</form>






javascript angular firebase google-cloud-firestore angularfire2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 15:34









Frank van Puffelen

243k29387414




243k29387414










asked Mar 8 at 11:12









MenaMena

435823




435823












  • How do you query for the from and to? Through the route parameter I guess, but how are these related?

    – Renaud Tarnec
    Mar 8 at 11:20











  • @RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

    – Mena
    Mar 8 at 11:37

















  • How do you query for the from and to? Through the route parameter I guess, but how are these related?

    – Renaud Tarnec
    Mar 8 at 11:20











  • @RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

    – Mena
    Mar 8 at 11:37
















How do you query for the from and to? Through the route parameter I guess, but how are these related?

– Renaud Tarnec
Mar 8 at 11:20





How do you query for the from and to? Through the route parameter I guess, but how are these related?

– Renaud Tarnec
Mar 8 at 11:20













@RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

– Mena
Mar 8 at 11:37





@RenaudTarnec I used a form to get from to & date values. The values for from & to are then concatenated and used as route value. I have added the form code

– Mena
Mar 8 at 11:37












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062011%2ffirebase-query-not-returning-results-everytime-it-runs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062011%2ffirebase-query-not-returning-results-everytime-it-runs%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229