Is it possible to make ng-models get default values, like ''
?
I have a form on which I have used jQuery's serialize
function, and whenever a a value is not present, it will still include it in the serialized data, E.g. {name: '', age: ''}
.
However, when I use try using posting it by using Angular's $http
and getting the model from $scope
, it appears as undefined
when it is empty.
You may also try:
<div ng-init="foo={}">
<input type="text" ng-model="foo.name=''"/>
</div>
or:
<input type="text" ng-init="foo.name=''"/>
it will present:
foo = { name: '', .... }
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