2015-04-16 22 views
1

我知道角度不发送表单POST中的空字段,但我想完全相反。如果一个字段存在于html表单中,那么这个字段必须被发布并不重要,如果它的空白或有一些数据,以便我可以在我的函数中获得该字段。以角度形式发送空POST字段

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

如果字段中的函数存在为什么不查? – detheridge02

+0

@ detheridge02我想在我的功能这个空的领域,我不想检查它的空或不。我想检查它在POST中是否存在,字段是动态的,所以我不知道字段的数量。因此,如果某个字段仅存在于POST中,则可以使用自定义数据(默认值)填充该字段,但空字段必须发布。 –

回答

3

您可以使用空数据初始化您的字段。

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

OR:创建一个指示

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 /> 
+0

是的,它的工作原理,谢谢:) –

+0

@ n.imp我很高兴它可以帮助你 – Reena