I have these two inputs:
<input type="date" ng-model="year">
<input type="time" ng-model="time">
I want to create a Date object from these two values. Something like this:
new Date(year, time);
how can I do that?
I have these two inputs:
<input type="date" ng-model="year">
<input type="time" ng-model="time">
I want to create a Date object from these two values. Something like this:
new Date(year, time);
how can I do that?
You can manually add the two dates together in your controller. If you want this to automatically update on your controller scope, then you can use a watch expression in tandem with the date arithmetic. For example:
$scope.$watchGroup(['year', 'time'], function (values) {
var year = values[0], time = values[1];
$scope.date = new Date(year.getYear(), year.getMonth(), year.getDay(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds());
});
Then you can use date on your scope however you wish, and it will automatically update whenever year or time change.
Note that built-in support for input[type=date] is only available in Angular 1.3.x or later. Earlier versions will not give you access to the date in your model.