0

I have a component that somewhere inside that component it has a code like this:

var getAttribute = $parse(attrs[key]);

when $parse service is passed a string like this2017-03-06 14:40:19 it fails and produce the following error:

Error: [$parse:syntax] Syntax Error: Token '14' is an unexpected token at column 12 of the expression [2017-03-06 14:40:19] starting at [14:40:19].

can anyone tell me what is wrong with this whole thing?

2

1 Answer 1

1

$parse is a service which accept only string as arguments. So processing date object is not possible through $parse service. so first apply your date object to $filter. Then the result will be a string type. Which can be accessible through $parse service.

var collectionDate = '2002-04-26T09:00:00'; 
collectionDate = $filter('date')(collectionDate, 'dd/MM/yyyy'); //string format
collectionDate = $parse(collectionDate);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your answer, but I still have problem with your solution, I use it like minDate: $filter('date')(new Date()) and it gives me the error Error: [$parse:syntax] Syntax Error: Token '6' is an unexpected token at column 5 of the expression [Mar 6, 2017] starting at [6, 2017]., am I doing something wrong?
I could have know the scenario that you are looking for?
if you take a look at here: github.com/AminRahimi/angular-bootstrap-persian-datepicker/blob/…, I am passing some options to a directive and that directive internally use $parse service for those options which in this case are date objects and that causes error.

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.