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 !
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?: