I'm getting data from SQLite and assign it to my $scope.loans:
{
"id": 1,
"book_id": 2,
"patron_id": 3,
"loaned_on": "2016-12-28",
"return_by": "2017-01-25",
"returned_on": "2017-01-17",
}
{
"id": 2,
"book_id": 3,
"patron_id": 4,
"loaned_on": "2016-12-28",
"return_by": "2017-01-25",
"returned_on": null,
}
In my view I'm trying to bind the data into inputs tags so the user can edit and submit the changes (I'm using pug template engine)
table
thead
tr
th Loaned On
th Return By
th Returned On
tbody
tr(ng-repeat='loan in loans')
td(type='date' ng-model='loan.loaned_on' value='{{loan.loaned_on}}')
td(type='date' ng-model='loan.loaned_on' value='{{loan.return_by}}')
td(type='date' ng-model='loan.loaned_on' value='{{loan.returned_on}}')
Now I'm getting an AngularJS error says that the ngModel is not a date object.
I understand that I should use the date constructor to convert the date string to a date object, But my question is what is the best way to do such a thing?
solution
I thought that maybe I'll find a better way, but I didn't.
So I loop through the loans array and assign a date object for each date string.