Search code examples
angularjsdateangularjs-directivemilliseconds

How to bind View Date to model milliseconds with Angularjs


I want to bind an input of type Date on the view
to a milliseconds property in the model with Angularjs.

For example :
the user set "09/23/2014" into the field
and angularjs automatically set "1411423200000"
into the model property binding with the input.

I don't find any directive or filter to do that.

Thanks for your help.


UPDATE to detail my question.

Is there a "native" way in Angularjs to intercept
model to view AND view to model and convert my data ?


Solution

  • I found a solution with :

    ngModel.$parsers.push(fromUser);  
    ngModel.$formatters.push(toUser);  
    

    With that, i change dynamically the data format during the binding.

    See full solution in jsfiddle