I have a form with mandatory and non mandatory fields. If I do not enter any data into the non mandatory fields, undefined is passed by default instead of a null string/ empty object/ empty Array. As a result, this variable is not stored in the DB at all
Is there any Generic way to pass an empty string/object/array instead of undefined when the field is left blank?
You can initialize the model with a space using ngInit directive. Like
<input type="text" ng-model="testModel" ng-init="testModel=' '" />
This way the model is always initialized to space character and will be sent in the query parameter therefore it will stored in the database. If the user types any text the value will be updated in model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With