Multiple instances of child being added and modified are being triggered repeatedly

I am currently developing an app using both Ionic and Firebase as the backend. I have implemented code to watch for two separate events using child added and child changed, but I am running into an issue where it is firing multiple times. When checking the Firebase data, I only see one child added instead of the expected two. Here are snippets of the problematic code:

1.

  new Firebase("https://unique-firestore-8563.firebaseio.com/btr/users/acceptedBySender/myid/").on("child_added",function(data,prevchild){

    console.log('added just fired');

       //this console log appears twice

 });

2.

    new Firebase("https://unique-firestore-8563.firebaseio.com/btr/users/posted/myid/").on("child_changed",function(data){

       console.log('changed just fired');

       //this console log appears eight times

    });

Answer №1

After some troubleshooting, I was able to find the solution to this issue. It appears that the problem was caused by the controller reloading because it was connected to multiple views. Every time it reloaded, a new 'watcher' was created. Hopefully, this explanation clarifies things.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving the value of a hidden field in JavaScript following the execution of a PHP

I am facing an issue with my code. There is a JavaScript function on my page and a PHP function that populates a hidden field. However, when I try to retrieve the value of the hidden field from JavaScript, it does not seem to reflect the current value. It ...

Continuously building up with the setInterval function

Is it possible to create a 'flash' effect for a list using setInterval in JavaScript? I've noticed that if I leave the page open and return after some time, the setInterval seems to be running every 1 second instead of every 10 seconds. It ...

What could be the reason for the variable not resetting in my event handler?

Check out the code I've written below: $(document).ready(function () { var default_var = 2; var show_var = default_var; var total_var = 8; var increment_var = 2; var start_var = show_var+1; var end_var = show_var+increment_v ...

"Exploring the power of AJAX, manipulating strings with JavaScript, and building

In the process of creating a pyramid web app, I am currently working on integrating the JavaScript markdown editor EpicEditor for editing markdown files. $.ajax({ url: "{{ request.resource_url(context) }}raw_markdown", context: document.body, ...

What could be the reason for the selection box in my form not changing the items when togg

I'm having an issue with my form selection box code that used to work but is now not functioning properly. Could someone please help me identify where the error lies? Essentially, I have a form with the ID #main and a select box named #chart-type. Th ...

Generate a pair of dates and organize them in chronological order

Working on an application where the database response lacks a direct timestamp, causing data to render differently each day and requiring me to use .reverse() to fix my charts. I aim to implement a permanent solution using sort(), but struggling due to the ...

JavaScript for Image Preloading on iOS Devices

Scenario In my project, I have two images called 'car-light.png' and 'car-dark.png'. When a user interacts with the image named car-light.png, it transforms into car-dark.png. Here is the code snippet that represents this functionalit ...

Issue with rendering dynamic data in a bar chart using React.js

I am currently facing an issue where I am trying to retrieve data from a database and display it as the x-axis labels in a bar chart. import React, { useState, useEffect } from "react"; import "../styling/ClassGrades.css"; import { Bar ...

Is it possible to call a JavaScript file located inside a Maven dependency's jar?

In the process of developing a Spring MVC web application using Apache Tiles, I have incorporated JavaScript libraries such as JQuery by including them in the pom.xml file as dependencies. My query pertains to whether I can access these scripts from within ...

Is there a way to ensure that the onChange event of ionic-selectable is triggered twice?

I've been working with an ionic app that utilizes the ionic-selectable plugin, and for the most part, it's been running smoothly. However, I encountered a rare scenario where if a user on a slow device quickly clicks on a selection twice in succe ...

The Tic Tac Toe game is eagerly anticipating input from the user

I encountered an issue while trying to develop a tic-tac-toe game without AI. My click function seems to be triggering automatically. Can someone help me understand why this is happening? Below is the snippet of HTML code. <!DOCTYPE html> <html l ...

Sometimes Google Maps API doesn't load properly on my page until I hit the refresh button

Occasionally, I encounter a problem where my Google Map fails to load when the webpage is first opened, resulting in a blank map. However, upon refreshing the page, the map loads correctly. The error message appearing in the Chrome console reads as follow ...

The speed at which Angular is hiding elements is too rapid for any animation to keep up with

Utilizing Angular 1.2 in conjunction with the animate.css library available at The animations I'm implementing are geared towards simple ng-show="somevalue". The ng-show animations are functioning properly, smoothly fading in. However, when the eleme ...

Ways to both retrieve a variable and clear it simultaneously

In my validator library, there are functions that sanitize and validate strings. These validator functions add error messages to an array called "errors" for each invalid input they encounter. After completing validation on all inputs, I collect the error ...

A guide on using jCrop to resize images to maintain aspect ratio

Utilizing Jcrop to resize an image with a 1:1 aspect ratio has been mostly successful, but I've encountered issues when the image is wider. In these cases, I'm unable to select the entire image. How can I ensure that I am able to select the whole ...

Displaying the active nav-item on a collapsed Navbar in Bootstrap 4

As I dive into creating a responsive navbar using bootstrap, one particular aspect is puzzling me. I want the navbar to collapse at a certain viewport width and when it does, I wish for the 'navbar-brand' to disappear. Instead, I envision the act ...

jQuery - Incorrect folder path for image replacement

I have a specific request to change the image paths in multiple .html pages, redirecting them from the default folder to another folder. After implementing code from an external javascript file successfully, I am encountering an error where the HTML sou ...

Utilize Bootstrap tooltips to display live results fetched via an AJAX call

I have a bootstrap tooltip that I am trying to populate with data from an AJAX request. The text retrieved from the request should be displayed as the title property of the tooltip. Despite successfully executing the AJAX request, I am facing two issues: ...

Discovering duplicate values in an existing array and storing them in a new array in AngularJS can be achieved by iterating through the

/Here is my JSON data./ $scope.fund = [ { id: 1, fundname: 'HDFC Medium Term Opportunities-G', date: '12/05/2016', amountunits: '11120', price: '200&apo ...

Connect with Friends - Using Express, MongoDB, and EJS for a Seamless Friend Connection

I have been working on creating a social network that allows users to send and interact with friend requests. Currently, I have completed the registration, log-in, and "search for other users" functions. Once I find and select another user, I am able to d ...