n.imp
n.imp

Reputation: 807

Send empty POST field in Angular form

I know angular do not send empty fields in form POST but i want exactly opposite of that. If a field is exist in form html then that field must be posted doesn't matter if its blank or have some data so that I can get that field in my function .

 <input type="hidden" class="form-control" ng-model="formData.field_name]" ng-trim="false"/> 

Upvotes: 1

Views: 1285

Answers (1)

Reena
Reena

Reputation: 1119

You can initialized your field with the empty data.

 One <input name="one" ng-init="value = ''" ng-model="value"  /><br /> 
 Two <input name="one" ng-init="value2 = ''" ng-model="value2" /><br />

OR :Create a directive

myApp.directive('initializeProperty', function() {
  return {
      restrict: 'A',
      link: function (scope, element, attr) {
        element.val('');
      }
  };
});


 One <input name="one" ng-model="value" initialize-property ng-trim="false"  /><br /> 
 Two <input name="one" ng-model="value2" initialize-property ng-trim="false" /><br />

Upvotes: 3

Related Questions