angularjs - angular material date picker field value empty -


i want date of birth of user, predefined min , max date working fine. , date format want dd-mm-yyyy, have defined following in config;

app.config(['$mddatelocaleprovider', function ($mddatelocaleprovider) {       $mddatelocaleprovider.formatdate = function(date) {          return moment(date).format('dd-mm-yyyy');       }}]); 

and controller has

    $scope.user = {};     $scope.user.dob = new date();     $scope.maxdate = new date(        $scope.user.dob.getfullyear() - 10,        $scope.user.dob.getmonth(),        $scope.user.dob.getdate()     );     $scope.mindate = new date(        $scope.user.dob.getfullyear() - 120,        $scope.user.dob.getmonth(),        $scope.user.dob.getdate()     ); 

and html is;

<md-datepicker   ng-model="user.dob"   md-placeholder="enter date of birth"  md-min-date="mindate"   md-max-date="maxdate"> </md-datepicker> 

with code field shows current date default, don't want,

i want date field empty default.

also want values in both ways follows 1) date-month-year , 2) date-month-year hour-minutes-seconds

when tried value shows "09-11-2016t18:30:00.000z"

i want either "09-11-2016" or "09-11-2016 18:30:00"

your mddatelocaleprovider doesnt check null values.

your problem is:

app.config(['$mddatelocaleprovider', function ($mddatelocaleprovider) {   $mddatelocaleprovider.formatdate = function(date) {      return moment(date).format('dd-mm-yyyy');   }}]); 

it needs like:

$mddatelocaleprovider.formatdate = function(date) {    var m = moment(date);    return m.isvalid()? m.format('dd-mm-yyyy') : ''; }; 

then can set

$scope.user.dob=null; 

and empty datepicker.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -