0

I'm trying to set a default value in my ionic date picker but it just seems to be ignored.

The versions are; Ionic "1.3.2" Node v14.15.4 AngularJS v1.8.0 ion-datetime-picker.min.js (not sure of this version)

So far I've tried this;

                <div class="row">
                    <div class="col col-33">
                        <strong>&nbsp;DOB: </strong>
                    </div>

                    <div class="col">
                        <span ion-datetime-picker date ng-model="data.demographics.pmiDOB">
                            {{data.demographics.pmiDOB | date: "dd/MM/yyyy"}}
                       </span>
                    </div>
                </div>
$scope.data.demographics.pmiDOB = "2022-04-21"; //new Date(1974,3,24).toISOString();

I understand that the date picker needs an iso date format but no matter what I try the date picker when rendered just shows today's date?

Thx.

2
  • I can't even find Ionic 1 datepicker documentation using AngularJS. Most of my experience with ionic is v3+ using modern Angular. I am confused why you have a binding in the content area for your element using the ion-datetime-picker directive? Does the directive not display the current value? Also, do you have a link to the Ionic v1 docs?
    – Mark Clark
    Commented Feb 7, 2023 at 17:49
  • Unfortunately, I don't have any documentation either for ionic v1
    – Mark
    Commented Feb 9, 2023 at 12:35

1 Answer 1

0

I found the solution with this;

                let dateString = $scope.data.demographics.pmiDOB;
                let [day, month, year] = dateString.split('/')
                const dateObj = new Date(+year, +month - 1, +day)

                $scope.data.demographics.pmiDOB = dateObj;

Not the answer you're looking for? Browse other questions tagged or ask your own question.