How CornerJS Date by json

I am new to angularjs, I am trying to associate the date property with input (text), but I don't know how to format the date.

my json object controler:

$scope.datasource = {"prop1":"string data", "myDateProp":"\/Date(1325376000000)\/"} 

my opinion:

 <input type="text" ng-model="datasource.myDateProp" /> 

as a result, I get the string "/ Date (1325376000000) /" in my text box.

How can I format this date?

+7
source share
1 answer

<y> What you need to do is look at http://docs.angularjs.org/api/ng.filter:date , which is the default filter available in angular.

It seems that you are transmitting additional material with a date. See the script here. (/ Date ( *) /). With the exception of the material in * everything else does not need to parse the date, and the default angular filter will not be able to parse it. Either separate these additional materials from the model, or, alternatively, you can write your own filter to break them into the input. C>

EDIT:

Take a look at http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController (and the example that is defined there!). If you intend to reuse this in several places, I suggest you do it in the method described by ngModelController. Create a new directive and implement $ render and $ setViewValue on ngModel.

If you just want to do this in one place, an alternative would be to define a new model for input. Something like

 $scope.dateModel = ""; 

and use it

 <input type="text" ng-model="dateModel" ng-change="onDateChange()"/> 

In your controller, you will need to do something like:

 $scope.$watch("datasource.myDateProp",function(newValue){ if(newValue){ convert(newValue); } }); function convert(val){ //convert the value and assign it to $scope.dateModel; } $scope.onDateChange = function(){ // convert dateModel back to the original format and store in datasource.myDateProp. } 
+3
source

All Articles