I'm doing some simple data binding like so:
<input type="text" class="form-control" model="amount">
<label>Your amount is {{amount * 10 }}</label>
However, initially, when the text input is empty it returns NaN.
How can I prevent this from happening with Angular?
You can try this:
<input type="text" class="form-control" model="amount">
<label>Your amount is {{ (+amount) * 10 }}</label>
HTML text inputs are text by definition. the added + will convert it to an number prior to being used.
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