0

I am trying to set a default date for ui bootstrap datepicker. The dates are coming from json and are in Unix timestamp format.

[ 
    { "type": "date", "name": "date 1", "value": 1375907474 },
    { "type": "date", "name": "date 2" },
    { "type": "date", "name": "date 3", "value": 1378590263 }
]

inside a directive, i am trying to convert the date and to bind it to ng model

scope.dt = $filter('date')(scope.required.value*1000);

but it gives a javascript error :

TypeError: Object Sep 7, 2013 has no method 'getFullYear'

here is a plunker : http://plnkr.co/edit/a9gfH8?p=preview

What am i doing wrong ?

1 Answer 1

3

The error you are seeing is the result of this:

"Sep 7, 2013".getFullYear()

What you want is this:

new Date("Sep 7, 2013").getFullYear()

Somewhere you're passing angular a string instead of a date object.

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.