Having an issue retrieving user information by searching firstname in Mongo DB using Mongoose schema. The response includes the firstname and booking date, but the date is returning as undefined with the error message Error: [ngModel:datefmt] Expected `2017-11-06T16:00:00.000Z to be a date. It seems like the problem lies in the fact that type=date expects an object while the JSON is returning a string.
I am relatively new to Angular JS and have attempted various suggested solutions without success. I'm unsure of what I may be missing. Any specific advice based on the provided code would be greatly appreciated.
https://i.sstatic.net/N87Kl.png
HTML
<form name="updateBookingsForm" ng-repeat="booking in ctrl.bookings" novalidate>
<input name="firstname" type="text" ng-model="booking.firstname" class="form-control" required>
<input name="date" type="date" ng-model="booking.date" class="form-control" required>
</form>
Controller
self.searchAllBookings = function () {
paAppAPI.searchAllBookings(self.term).then(function (result) {
console.log(result); //returns array and date undefined
self.bookings = result;
}
}).catch(function (err) {
console.log(err);
if (err.status == 404) {
self.message = "No bookings found";
self.showMessage = true;
}
});
}
Service
self.searchAllBookings = function (term) {
var defer = $q.defer();
$http.get("/api/booking?keyword=" + term).then(function (result) {
console.log(result); //returns array but date undefined
if (result.status == 200) {
defer.resolve(result.data);
}
else {
defer.resolve(null);
}
}).catch(function (err) {
console.log(err);
defer.reject(err);
});
return defer.promise;
}
Server
app.get("/api/booking?", function (req, res) {
console.log("Search booking > " + req.query.keyword);
var keyword = req.query.keyword;
Booking.find({
"firstname" : new RegExp('^'+keyword+'$', "i")
}, (err, result) => {
if (err) {
console.log(err);
}
res.status(200).json(result);
console.log(result);
// { _id: 5a1a4e1238dfaa65e5fa59a2,
// firstname: 'Emily',
// date: 2017-11-20T16:00:00.000Z,
// __v: 0 },
console.log(result[0].date); //2017-11-06T16:00:00.000Z
});
});