0

I am getting error while populating date value in date field

I have the date input field,

<input type="date" data-ng-model="personalDetailsObj.personalDetails.dob" name="dob" value="{{personalDetailsObj.personalDetails.dob}}" pattern="dd/MM/YYYY"/> 

I am getting the DOB value from server like this,

$scope.kycinfo  = {
   "title": "Mr",
   "name": "vishnu",
   "dob": "22-06-1980",
  };

I am getting error When i try to set the value like this,

$scope.personalDetailsObj.personalDetails.dob = $scope.kycinfo.dob;

Error saying, Error: [ngModel:datefmt] Expected 22-06-1980 to be a date

4
  • You don't need value attribute when you are using ng-model Commented Dec 18, 2015 at 5:22
  • i removed, but how do i set the value in input field Commented Dec 18, 2015 at 5:26
  • type='date' model need date type value your are providing him string type value Commented Dec 18, 2015 at 5:28
  • set dob as a date type Commented Dec 18, 2015 at 5:30

1 Answer 1

1

If you are using moment.js (if not use it), then try this

$scope.personalDetailsObj.personalDetails.dob = moment($scope.kycinfo.dob);

otherwise using simple javascript (not recommended)

$scope.personalDetailsObj.personalDetails.dob = new Date($scope.kycinfo.dob);

Also no need of value attribute when you are already using ng-model

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.