2

When I click on the datetimepicker button it clears the date.

'use strict';

app.directive('defaultDate', function () {
    return {
        restrict: 'E',
        templateUrl: 'app/directives/default-date.html',
        scope: {
            onChange: '&',
            obj: '='
        },
        controller: function ($scope) {
            $scope.alterou = function () {
                $scope.onChange()
            }

            $scope.openCalendar = function (e) {
                e.preventDefault()
                e.stopPropagation()
                $scope.obj = { isOpen: true };
            };
        }
    }
})

<p class="input-group">
  <input type="text" class="form-control" ng-change='alterou()' datetime-picker="dd/MM/yyyy HH:mm" ng-model="obj.date" is-open="obj.isOpen" />
  <span class="input-group-btn">
    <button type="button" class="btn btn-default" ng-click="openCalendar($event, prop)"><i class="fa fa-calendar"></i></button>
  </span>
</p>

I would expect that the calendar shall not clear the date by just opening it.

Manish Balodia
  • 1,863
  • 2
  • 23
  • 37
  • Can you create a JSFiddle where your problem can be reproduced? Some of us might want to play around with the issue before answering. – Lajos Arpad Jun 19 '19 at 13:49

1 Answers1

0

The issue is this line in your $scope.openCalendar function:

$scope.obj = { isOpen: true };

You are setting $scope.obj to an object with a single property of isOpen. What you should be doing here is:

$scope.obj.isOpen = true;

That way the value of $scope.obj.date will be preserved.

Lex
  • 6,758
  • 2
  • 27
  • 42