0

I want to assign my string date to ui-date

my view

 <input ng-switch-when="datePicker" type="text" ui-date-format ui-date class="form-control" ng-model="field.value" />

and my date string "12/12/2015"

but I got this error "Error: ng-Model value must be a Date object - currently it is a string - use ui-date-format to convert it from a string"

Please someone help me, thank

1 Answer 1

1

Try doing as it says (Error: ng-Model value must be a Date object) in controller

$scope.field.value = new Date($scope.field.value);

Or add an date-format attribute with your date mask to the input tag

ui-date-format="DD/MM/YYYY"
Sign up to request clarification or add additional context in comments.

10 Comments

I have tried your first option,It's not error, but the view (input) is blank the second option , I still got the same error.
oh, sorry thats should be - ui-date-format="mm/dd/yy"
could you show all the code html/js of your case? - seems that something else results this error
I can not reply your comment with code style, so i have posted other answer for you
ohhhh, its a mess >_< can you in your template add near to this line ' <input ng-switch-when="datePicker" type="text" ui-date-format="mm/dd/yy" ui-date class="form-control" ng-model="field.value" />' the following - '{{field.value}}' - so that we can see what value is there
|

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.