Im trying to pass the date from a date picker value into a $http session parameter (like "2017-12-7"), but the date my datepicker Date variable is 'undefined'
angular.module('MyApp', ['ngMaterial']).controller('MyController',
function($scope, $http) {
this.myDate = new Date();
this.minDate = new Date("December 4, 2017");
this.maxDate = new Date("December 10, 2017");
$scope.getDataFromServer = function() {
var dt = this.myDate;
$http({
method : 'GET',
url : 'myurl',
params : {
pdate : this.myDate
}
}).then(function mySuccess(response) {
$scope.datacontainer= response.data;
}, function myError(response) {
});
};
});
The $scope.getDataFromServer method is called when you click a button. The following line var dt = this.myDate; was to look at the myDate object in chrome DevTools (F12) and it says 'undefined'.
The date picker HTML is as follows:
<div flex="20">
<md-datepicker ng-model="myDate" md-placeholder="Enter date" md-min-date="ctrl.minDate" md-max-date="ctrl.maxDate">
</md-datepicker>
</div>