g00fy- / angular-datepicker

calendar and datepicker directives for angular
MIT License
719 stars 420 forks source link

Issue with format #205

Open pankas87 opened 8 years ago

pankas87 commented 8 years ago

I'm using the input datepicker and everything works great except for the format.

When I don't use the format attribute it displays the date correctly with the default format but when I add the format attribute all I can see are strange characters.

DatePicker

Here's my code for both the angularJS controller and the view

<div class="deletion-date">
  <input date-time format="deletion_date.format" id="deletion-date-picker" max-view="month" min-view="date" name="deletion-date-picker" ng-model="deletion_date.date" view="date" />
</div>
angular.module('mapping.controllers').controller('CompartirMapaCtrl', [
  '$scope',
  '$http',
  'map_views_repository',
  '$rootScope',
  'user_profiling',
  'safeApply',
  function($scope, $http, map_views_repository,$rootScope,user_profiling,safeApply) {
    // Inicializaciones de fecha
    var today   = moment.tz('UTC').hour(12).startOf('h');

    //Funciones de compartir mapas
    $scope.sharing_users        = [];
    $scope.sharing_email        = null;
    $scope.share_editable       = false;
    $scope.sharing_map_id       = map_views_repository.map_id;
    $scope.user_profiling       = user_profiling;    
    $scope.deletion_date        = {date: null, min_date: today, format: 'LL'};
}]);

(Both are simplified versions)

Am I missing some parameters or configuration?

DanTalash commented 8 years ago

I think it is because currently format expects a string as opposed to a variable to watch. It's passing the string deletion_date.format to momentjs to format your date.

If you put curly braces around the param so that angular inserts the variable contents into the attribute, it would work. Such as, format="{{::deletion_date.format}}". The two colons mean it will be a one-time binding, and angular will not bother checking if this value has changed. If you need to change the format, you should use a pickerUpdate event.

pankas87 commented 8 years ago

This one worked perfectly, it can be closed I guess