jeudi 29 octobre 2015

Firebase Retrieves Item multiple times (Everything is doubled)

So I call the function that fetches data from Firebase and push that data in an Array of objects. However, for some reason I have two of everything, everything is doubled as if the retrieve function gets called twice!

Here is how it looks:

link to image

Code:

cApp.controller('HomeCtrl', function($scope, $ionicModal, $rootScope) { 

$scope.allMeals = [];


    // getting meals from database
    $scope.getMeals = function () { 
    $scope.allMeals = [];

        var mealsRef = new Firebase("https://<my app id here>http://.firebaseio.com/Meals"); 

    mealsRef.on("child_added", function(snapshot) {
    var newPost = snapshot.val();
    console.log("Name: " + newPost.name);
    console.log("Price: " + newPost.price);

      $scope.allMeals.push({
        name: newPost.name, 
        price: newPost.price
      })
  });

 };


// calling get meals function
$scope.getMeals();

This is starting to give me headache!




Aucun commentaire:

Enregistrer un commentaire