katemihalikova / ion-datetime-picker

Date and/or time picker for awesome Ionic framework
MIT License
169 stars 101 forks source link

Getting the selected datetime #81

Closed devqik closed 7 years ago

devqik commented 7 years ago

I have used this code in codepen http://codepen.io/asterzwx/pen/dMLwaO To get the selected date and time from the calander but it doesn't seem to work I always get the current date and time for the day i am in. Thank you.

katemihalikova commented 7 years ago

Problem with getting current date instead of selected value is duplicate of #14. Problem with formatting value in input is duplicate of #45/#21.

devqik commented 7 years ago

I have followed your instructions in the previous issues but i always get the current date not the selected date

Here is my code

angular.module('starter.controllers', ['ui.rCalendar', 'ion-datetime-picker'])

.run(function($ionicPickerI18n, $rootScope) {
        $rootScope.datetimeValue = new Date();
        $ionicPickerI18n.weekdays = ["Sun", "Mon", "Tus", "Wed", "Thu", "Fri", "Sat"];
        $ionicPickerI18n.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
        $ionicPickerI18n.ok = "OK";
        $ionicPickerI18n.cancel = "Cancel";
        $ionicPickerI18n.okClass = "button-positive";
        $ionicPickerI18n.cancelClass = "button-stable";
 })

.controller('AddCtrl', function($rootScope, $stateParams, $ionicPopup) {

    $rootScope.showPopup = function(){

     var alertPopup = $ionicPopup.alert({
        title: 'Alert',
        template: 'Your selected time ' + $rootScope.datetimeValue //here Im trying to get the user's selected time
   });   
   }  
});
<ion-view view-title="Add Tabel">
  <ion-content class="padding">

<div style="margin-top:25px; border:none;" class="item item-icon-left" ion-datetime-picker date time data-ng-model="datetimeValue">
                <i class="icon ion-calendar positive"></i>
                Start Date:
                <p id="date">{{datetimeValue| date: "EEE MMM dd yyyy h:mm a"}}</p>
            </div>
</ion-content>
</ion-view>

I am so sorry but i will really appreciate your help if this is fixed. Thanks in advance.

katemihalikova commented 7 years ago

The answer in #14 basically says Always put a dot in your models. You have ng-model="datetimeValue". Refactor it to have a dot, e.g. ng-model="$ctrl.datetimeValue". You just need to use your very basic angular skills to fix this.