1

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"/> 
2
  • Why not check if the field exists in your function? Commented Apr 16, 2015 at 12:16
  • @detheridge02 I want this empty field in my function , I don't want to check wether its empty or not . I want to check wether it exists in POST or not and fields are dynamic so I don't know the number of fields . So If a certain field just present in POST then I can populate it with custom data (default value) but for that empty fields must get POSTed. Commented Apr 16, 2015 at 12:22

1 Answer 1

3

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 />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.