0
votes

I use Ionic and AngularFire for make my app, but I have problem:

My requests are not recorded in the database, when I click the submit button the following error is invoked console: TypeError: Cannot read property 'push' of undefined. I do not know what to do ... Help me please. I am at your disposal for any further information.

Here is my html code:

<form ng-submit="AddEvent()">
  <label class="item item-input item-stacked-label">
    <span class="input-label"><i class="fa fa-pencil"></i> Nom de l'événement</span>
    <input type="text" ng-model="events.nameid">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label"><i class="icon ion-ios-information"></i> Description</span>
    <br><textarea ng-model="events.descriptionid"></textarea>
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label"><i class="fa fa-location-arrow"></i> Adresse</span>
    <input type="text" ng-model="events.addressid">
  </label>
<button class="button" type="submit" id="success-btn-create"><i class="fa fa-arrow-right"></i></button></form>

My Controller JS :

myApp.controller('Step1Ctrl', ['$scope', 'Events', 'Auth', '$rootScope', '$state', function($scope, $Events, Auth, $rootScope, $state) {

  $scope.events = Events;
  var Events = {fbRef: "https://myApp.firebaseio.com/Events"};


  $scope.AddEvent = function() {
  var eventsRef = eventsRef.push();         
      $scope.events.push({
      "nameid": nameid,
      "descriptionid": descriptionid,
      "addressid": addressid,

    });

    }

  $scope.auth = Auth;

    // any time auth status updates, add the user data to scope
    $scope.auth.$onAuth(function(authData) {
      $scope.authData = authData;
    });

    $scope.create = function() {
    $state.go('tabstep1');
};
$scope.close = function() { 
     $state.go('tabdash'); 
};
}])

My Service JS :

angular.module('starter.services', ['ngCordova','firebase'])

myApp.factory("Events", ["$firebaseArray", function($firebaseArray) {
  var eventsRef = new Firebase("https://myApp.firebaseio.com/Events");
  return $firebaseArray(eventsRef);
}]);
1

1 Answers

0
votes

Your variable eventsRef is undefined when you call eventsRef.push(). Also you aren't doing anything in the push() call.

Try:

var eventsRef = [];
eventsRef.push(somethingToAddToEventsRef);