1

I use Ionic and AngularFire for make my CRUD app, but I have a (new) problem: The date and time are not recorded in the database. And I struggle to implement getTime () with the current structure of my code (Whether it's hard being a novice, especially when most Angularfire tutorials are outdated ...) ... I thank you all advance to help me! (This is a copy of my previously question, I hope one person can help me to debug my code)

This is my HTML :

<form ng-submit="submitEvent(event)">
      <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="event.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="event.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="event.addressid">
      </label>
<label class="item item-input item-stacked-label">
    <span class="input-label"><i class="fa fa-calendar"></i> Date</span>
    <input type="date" ng-model="event.dateid">
  </label>
  <label class="item item-input item-stacked-label">
    <span class="input-label"><i class="fa fa-clock-o"></i> Heure</span>
    <input type="time" placeholder="HH:mm:ss" ng-model="event.hourid">
  </label>

      <button class="button" type="submit" value="Add Event" id="success-btn-create"><i class="fa fa-arrow-right"></i></button></form>

This is my Controller JS (submitEvent only) :

$scope.submitEvent = function(event) {

var eventRef = new Firebase("https://myApp.firebaseio.com/Events");
Event.add(event).then(function (data){ 
  $scope.event = [{nameid: null, descriptionid: null, adressid: null, cpid: null, townid: null, dateid: null, hourid: null}];
 });

  }

My service JS :

myApp.factory("Event", ["$firebaseArray", function($firebaseArray) {
var eventRef = new Firebase('https://myApp.firebaseio.com/Events/');
    return {
         get: function (){
                return $firebaseArray(eventRef);
              }
            ,
        add: function (event){
          var eventInfo = $firebaseArray(eventRef);
          return eventInfo.$add(event);
              }
       }
}]);

Thanks all !

3
  • Look what I found.. stackoverflow.com/questions/31211482/… You already asked this yesterday Commented Jul 5, 2015 at 11:32
  • Yeah, I said the same things in the actual post : "I thank you all advance to help me! (This is a copy of my previously question, I hope one person can help me to debug my code)" Commented Jul 5, 2015 at 11:36
  • I found it before I read :D It's bad to post the same question again though. Try to promote the other instead Commented Jul 5, 2015 at 11:36

1 Answer 1

1
event.dateid = new Date(event.dateid).toJSON();
return eventInfo.$add(event);

inside the get function and here

$scope.event = [{nameid: null, descriptionid: null, adressid: null, cpid: null, townid: null, dateid: null, hourid: null}]; 

why set these to null? i think it should be set to value saved after saving?:

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for your time, I put this in my service ?
In controller, I replace dateid : null; by dateid : addedAt; ? :)
what were you using event.dateid to track before, event date? if it is event date then it needs another property addedAt which is invisible but added to every event that does not have it every time they are added, you might also want to tracked modifiedAt this will be update at every save, better to move it to the service where save to Firebase is called
To be simple, I want the user to enter the date of the event into the specified field (HTML) and I want to recover and get in database. It's the user define the date of his choice (And really sorry for my bad english, I'm french lol)
ok the you can use dateid or event.date does not really mater, but i think you should convert the event.date to string before saving. e.g see my update answer
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.