here on stackoverflow I found a directive made by an user for angularJS, for a input number spinner, and I was just looking for it!
All working good, but one thing is not, when you manually enter a number in the input field, and press MINUS, it s gonna subtract 1 from that number, all good here,
but when you input a number and as first thing you press PLUS, instead of adding 1, it's gonna add a "1" next to the number you wrote!
Only going "minus" once fixes it,
can someone help me fix the code to avoid this? I want that when I put the number manually, you can press on "plus" and get +1 on that number!
1, but concatenating it. E.g1+1gives2, whereas"1"+1gives"11". Minus doesn't have that property, so"11"-1gives10. A hack / quick fix for it is to cast a Number:scope.ngModel = Number(scope.ngModel) + 1;ng-patterndeletes the value if it doesn't fit the regex expression, leaving it asundefined. CastingNumber()only partially solves the issue. You can type such values as1.2.3, which bypasses the pattern as a valid number, but after casting a Number on it or doing+1or-1operations, the result is obviouslyNaN