I am struggling to get AngularJS to work properly with a small thing that I am trying to implement.
I have an input of type number (which likely causes the issue) which is bound to a variable in my controller, and I need to disable a button if this input is empty.
Here's the code for my input and button:
<input type="number" min="0" max="20" ng-model="student.mark">
<button ng-disabled="!student">Send</button>
I tried several solutions to disable my button if the field is empty, but enable it if it has a value of 0:
<button ng-disabled="!student || !student.mark">Send</button>
<button ng-disabled="!student || !angular.isNumber(student.mark)">Send</button>
<button ng-disabled="!student || student.mark == ''">Send</button>
<button ng-disabled="!student || student.mark === ''">Send</button>
None of those seem to work. It will work properly if I have any number in my input, but either the button will be disabled if I have the value "0", or the button will stay enabled if I put a valid value and then remove it.
What makes me think that it should work is the fact that if I display the value using {{ student.mark }}, the value 0 will indeed show as "0" and an empty input will show as empty.
Thanks.
ng-disabled="!student.mark"(maybe you need&&instead of||)