Question

I have made a datetime picker directive

 adocsModule.directive('dateTimePicker', ['$timeout', function ($timeout) {
        return {
            link: function (scope, element, attrs, ctrl) {
                $timeout(function () {
                    element.datetimepicker({
                        //language:  'fr',
                        weekStart: 1,
                        todayBtn: 1,
                        autoclose: 1,
                        todayHighlight: 1,
                        startView: 2,
                        forceParse: 0,
                        showMeridian: 1
                    });
                }, 10);
                scope.$apply();
            }
        }
    }]);

i have used this directive in html, its working fine but the issue is when i set the value by datetime picker, it never update the ng-model attribute. i got permision.dateFrom empty in controller. Please help me

<div ng-show="permission.showDuration">
                        <div class="form-group margin-left-20px margin-top-5px">
                            <input type="text" date-time-picker class="form-control font-11px input-style1"  placeholder="Select date from" ng-model="permission.fromdate" >
                        </div>
                        <div class="form-group margin-left-20px margin-top-5px">
                            <input type="text" date-time-picker class="form-control font-11px input-style1"  placeholder="Select date from" ng-model="permission.todate">
                        </div>
                    </div>
Was it helpful?

Solution

i once used datetime and this how i fixed

 .on('changeDate', function (ev) {                
                    $parse(attrs.ngModel).assign(scope, ev.date);
                    scope.$apply();
                });

you need to parse the attribute and then assign its value to model, and apply changes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top