AngularJS - Date filter
Simple example for Stack Overflow (http://stackoverflow.com/questions/18148546/angularjs-date-filter-incorrect-time)
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
<div ng-app ng-controller="MyCtrl">
</div>
JavaScript
function MyCtrl($scope, $filter) {
keepAllData = [];
$scope.setData = function(survey, choice) {
var item = $filter('filter')(keepAllData, {
surveyId: survey.id
});
if (!item.length) {
keepAllData.push({
'surveyId': survey.id,
'choiceId': choice.id
});
} else {
item[0].choiceId = choice.id;
}
console.log(keepAllData);
};
var obj = {
survey: {
id: 10
},
choice: {
id: 1
}
};
$scope.setData(obj.survey, obj.choice);
var obj1 = {
survey: {
id: 8
},
choice: {
id: 1008
}
};
$scope.setData(obj1.survey, obj1.choice);
var obj1 = {
survey: {
id: 10
},
choice: {
id: 100
}
};
$scope.setData(obj1.survey, obj1.choice);
}