Ariana Ariana - 7 months ago 19
HTML Question

Setting Minimum Value to a Substraction (AngularJS)

I would like to know how it is possible to set a minimum value of "0" to my substration (

100 - message.length
). I don't want negative values to be returned when the minimum number of caracteres (100) is verified (For instance: "Number of caracteres left: -55"). Thank you.

<tr>
<td colspan="2" align="center">
<textarea rows="10" cols="50" name="message" ng-model="message"></textarea>
</td>
</tr>
<tr>
<td align="center">Number of caracteres left: {{100 - message.length}}
</td>
</tr>
<tr>
<td align="center" colspan="2">
<button type="submit" class="btn btn-success" ng-disabled="(!message || message.length < 100)">Send</button>
</td>
</tr>

Answer

You could try something like this {{100 - message.length>0?100 - message.length:0}}