I\'m working on angular
application with Django
with rest-framework
..
The app receives it\'s info with json from the server.. O
Create a simple directive that converts the model value:
HTML:
<input date-input type="time" ng-model="created_time">
Directive:
app.directive('dateInput', function(){
return {
restrict : 'A',
scope : {
ngModel : '='
},
link: function (scope) {
if (scope.ngModel) scope.ngModel = new Date(scope.ngModel);
}
}
});
If you need to update all dates in Array with Objects
var data = [
{ id: "1" , birthday: "2016-01-20T11:24:20.882Z"},
{ id: "2" , birthday: "2016-01-20T11:24:20.882Z"},
{ id: "3" , birthday: "2016-01-20T11:24:20.882Z"},
];
function convertDataStingToObject (data) {
for(var i=0; i < data.length; i++ ){
console.log('string: ' + data[i].birthday);
data[i].birthday = new Date(data[i].birthday);
console.log('updated: ' + data[i].birthday);
console.log(typeof(data[i].birthday));
}
return data;
}
convertDataStingToObject(data);