katemihalikova / ion-datetime-picker

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

if this directive run in modal view, can't monitor click event #47

Closed plopen closed 7 years ago

plopen commented 7 years ago

if this directive run in modal view, can't monitor click event. it should be in $scope.on('modal.shown', function() { $element.on("click", $scope.showPopup); });

katemihalikova commented 7 years ago

Please create a demo demonstrating your issue.

plopen commented 7 years ago

In modal html code: `

now date time:
{{NextTask.planFinishTime | date: "yyyy-MM-dd HH:mm:ss"}}

`

in ion-datetime-picker directive code: `link: function($scope, $element, $attrs, ngModelCtrl) { $scope.dateEnabled = "date" in $attrs && $attrs.date !== "false"; $scope.timeEnabled = "time" in $attrs && $attrs.time !== "false"; if ($scope.dateEnabled === false && $scope.timeEnabled === false) { $scope.dateEnabled = $scope.timeEnabled = true; } $scope.mondayFirst = "mondayFirst" in $attrs && $attrs.mondayFirst !== "false"; $scope.secondsEnabled = $scope.timeEnabled && "seconds" in $attrs && $attrs.seconds !== "false"; $scope.meridiemEnabled = $scope.timeEnabled && "amPm" in $attrs && $attrs.amPm !== "false"; $scope.monthStep = +$scope.monthStep || 1; $scope.hourStep = +$scope.hourStep || 1; $scope.minuteStep = +$scope.minuteStep || 1; $scope.secondStep = +$scope.secondStep || 1;

            $scope.prepare();

            ngModelCtrl.$render = function() {
                $scope.modelDate = ngModelCtrl.$viewValue;
                $scope.processModel();
            };

            $scope.commit = function() {
                $scope.modelDate = new Date($scope.year, $scope.month, $scope.day, $scope.hour, $scope.minute, $scope.second);
                ngModelCtrl.$setViewValue($scope.modelDate);
            };

            var isModal = attr.isModal;
            if(isModal == true || isModal == 'true') {
              $scope.$on('modal.shown', function() {
                $element.on("click", $scope.showPopup);
              });
            }else {
              $element.on("click", $scope.showPopup);
            }

        }`

need judge whether this view is modal view, and monitor the click event in modal.shown.

katemihalikova commented 7 years ago

Works fine, see codepen. Do you have a different setup?

plopen commented 7 years ago

Do you have update the source code in github? No, I just fork and want to fix this issue in my branch, but I don't know how to mix to min.js.

plopen commented 7 years ago

in codepen, I can't show the modal, are you work with my modal.shown code or use your code?

katemihalikova commented 7 years ago

I have used your modal html, but haven't done any other change to the picker code.

It's working fine in Chrome on both PC and mobile. What's your environment?