I have a dynamic form that receives data from an array and iterates over it. In case of a date field I want to send in this format into the controller "dd/MM/yyyy" or "dd/MM/yyy hh:mm" tried to use the ng-bind but the controller receives in other format which is "Wed Dec 23 2015 00:00:00 GMT-0100 (Local Standard Time)", that should be the format to send via $http.post in a service.
Here is my field input
Only date:
<div class="form-field">
<label>{{fa.title}}</label>
<p class="input-group">
<input type="date" class="form-control"
ng-model="sendForm[fa.name]"
placeholder="dd/MM/yyyy"
ng-bind="sendForm[fa.name] | date:'dd/MM/yyyy'"/>
</p>
</div>
Date and hour:
<div class="form-field">
<label>{{fa.title}}</label>
<p class="input-group">
<input type="datetime-local" class="form-control"
ng-model="sendForm[fa.name]"
placeholder="dd/MM/yyyy hh:mm"
ng-bind="sendForm[fa.name] | date:'dd/MM/yyyy hh:mm'"/>
</p>
</div>
controller.js
app.controller("myAppCtrl", ["$scope", "SendForm", "FORMS", function ($scope, SendForm, FORMS) {
$scope.sendForm = function (form) {
SendForm.sendInfo(form,
function onSuccess() {
$scope.success = true;
},
function onError(message) {
$scope.error = true;
},
function onFinally() {
$scope.clearForm(form);
})
}]);
service.js
app.factory("SendForm", ["$http", "CONFIG", "FORMS","$httpParamSerializer", function ($http, CONFIG, FORMS,$httpParamSerializer) {
return {
sendInfo: function (form, onSuccess, onError, onFinally, message) {
var data = {
absolute: CONFIG.absolute
};
for (var i = 0, length = FORMS.form_variables.length; i < length; i++) {
if (angular.isUndefined(form[FORMS.form_variables[i].name])) {
var key = FORMS.form_variables[i].name;
var value = "";
data[key] = value;
} else {
var key = FORMS.form_variables[i].name;
var value = form[FORMS.form_variables[i].name];
data[key] = value;
}
}
var config = {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
};
$http.post(CONFIG.urlSendForm, $httpParamSerializer(data), config).success(function () {
onSuccess();
onFinally();
}
}]);