I'm having a problem with my Crud based ionic App with Firebase as backend. I have item.service which creates and writes object to Firebase, one of the properties is date object, which is added with input tag type=date, native. im ok with that at the, moment. Problem comes, when I try to update date property of my item, Im using ionic-datepicker by this fella (http://rajeshwarpatlolla.github.io/DatePickerForIonicFramework/demo/ "Demo").
in my controller code im calling $save function which saves/updates $scope properties to item.
$scope.updateItem = function () {
$scope.item.$save({
name: $scope.item.name
, serial: $scope.item.serial
, hirestart: $scope.item.hirestart.getTime()
, hireend: $scope.item.hireend.getTime()
, orderNumber: $scope.item.ordernumber
, category: $scope.item.category
});
//-------------------------
// **After making selection in date picker console logs value which is returned from datepicker. But nothing is pushed to Firebase data base.**
//********************************************** U-P-D-A-T-E****** for some reason I copied code above without, .getTime() attached to date objects, anyway I did try getTime() and valueOf() what it does it gets value in to the $scope but when I click Save the date fields in the form gets blank and transition to home.state. I tried console log inside save function and it logs value but nothing saved. //***************************************************************8
console.log($scope.item.hirestart.valueOf());
$state.go('menu.plantRegister');
};
Below is edit.html from which datepicker called.
<li class="item dark item-stacked-label item-icon-right">
<ion-note item-right class="calm"> Hire start date:</ion-note>
<label>{{item.hirestart | date:'dd-MMMM-yyyy'}}</label>
<i class="icon ion-ios-calendar-outline calm" ng-click="openStart()"></i>
</li>
<li class="item dark item-stacked-label item-icon-right">
<ion-note item-right class="calm"> Hire end date:</ion-note>
<label>{{item.hireend | date:'dd-MMMM-yyyy'}}</label>
<i class="icon ion-ios-calendar-outline calm" ng-click="openEnd()"></i>
</li>
And here's datepicker methods.
$scope.openStart = function (val) {
var ipObj1 = {
callback: function (val) { //Mandatory
console.log('Return value from the datepicker popup is : ' + val, new Date(val));
$scope.item.hirestart = new Date(val);
}
, disabledDates: []
, from: new Date(2012, 1, 1)
, to: new Date(2016, 10, 30)
, inputDate: new Date()
, mondayFirst: true
, showTodayButton: true
, disableWeekdays: [0]
, closeOnSelect: false
, templateType: 'modal'
};
ionicDatePicker.openDatePicker(ipObj1);
};
$scope.openEnd = function (val) {
var ipObj1 = {
callback: function (val) { //Mandatory
console.log('Return value from the datepicker modal is : ' + val, new Date(val));
$scope.item.hireend = new Date(val);
}
, disabledDates: []
, from: new Date(2012, 8, 2)
, to: new Date(2016, 8, 25)
, inputDate: new Date()
, mondayFirst: true
, showTodayButton: true
, closeOnSelect: false
, templateType: 'modal'
};
ionicDatePicker.openDatePicker(ipObj1);
};