c# - Selected date is not showing in datepicker in angular.js -


i working in mvc 5 project angular js. using date picker control

in webpage using directive in app.js.

myapp.directive('datepicker', function () { return {     restrict: 'a',     require: 'ngmodel',     link: function (scope, element, attrs, profilectrl) {         element.datepicker({             //dateformat: 'dd, d  mm, yy',             dateformat: 'dd-mm-yyyy',             autoclose: true,             onselect: function (date) {                 profilectrl.$setviewvalue(date);                 //profilectrl.$render();                 scope.$apply();             }         });     } }; }); 

everything works fine problem when select date it's shows selected date in date picker. example selected date june 1 2015

enter image description here

i save value on database. populate date picker again,

selected date not selected in date picker.

enter image description here

actually system date format dd-mm-yyyy.

edit :

please see html code below.

    <div ng-app="myapp" ng-controller="profilectrl">      .........      <div class="form-group">         <label for="dob" class="col-md-2 control-label">dob</label>          <div class="col-md-10">             <input type="text" datepicker name="dob" class="form-control" ng-model="models.dob" />          </div>      </div> 

angule controller code

$http.get("profile/getprofile").success(function (data) {      $scope.models = {         name: data.name,         useremail: data.useremail,         password: data.password,         confirmpassword: data.confirmpassword,         dob: data.dob,         address: data.address,         city: data.city,         country: data.country,         pincode: data.pincode,         phone: data.phone      }  }); 

c# controller

    public actionresult getprofile()     {          string _customerid = cookiehelper.getcookievalue(cookiehelper.enduser.userid);         long customerid = 0;          if (!int64.tryparse(_customerid, out customerid))             return json(null, jsonrequestbehavior.allowget);          customer customer = customerhelper.getcustomer(customerid);          if (customer == null)             return json(null, jsonrequestbehavior.allowget);          var data = new         {             id = customer.id,             name = customer.name,             useremail = customer.email,             password = customer.password,             confirmpassword = customer.password,             dob = (customer.dob != new datetime?()) ? ((datetime)customer.dob).tostring("mm/dd/yyyy", system.globalization.cultureinfo.currentculture) : string.empty,             address = customer.address,             city = customer.city,             country = customer.country,             pincode = customer.pincode,             phone = customer.phone         };          return json(data, jsonrequestbehavior.allowget);     } 

if dob field contain date value date picker not show date in

blue color, , date format different in page load , date changed event.

please help.

use momentjs manipulate date format suit datepicker field. check out here http://momentjs.com/ .your server side , client date formats might different.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -