ng-model seemingly not working in angularjs and ionic date picker

42 Views Asked by At

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.

1

There are 1 best solutions below

0
Mark On

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;