cordovang-showangular-ng-ifng-hideangularjs-ng-show

ng-if validator not working properly


I'm trying to show a phrase using ng-if / ng-show (with less or bigger than condition) validator but its not working 100% correct. Here's my code:

<p style="color: #fff; text-align: center; margin-top: 3px;" ng-hide="coin.cant_coin > '49'" > No enough cash!</p>

Here's my problem:

It works perfect from 50 to 99 but from 100 and bigger numbers its not working. I noticed that if I change value from 49 to 149 it works okay from 149 to 999 but stop working from 50 to 99. Same thing happens with ng-show and ng-hide. What could it be? and how can I fix this?


Solution

  • I think, your problem is not the validator but your expression.

    What type is coin.cant_coin? Is it an integer? Or is it a string?

    If your input is: 100 > 49, it works. However, if your input is: '100' > '49', then it doesn't work.

    I created a Plunker, which shows you the problem: https://plnkr.co/edit/OJfGD3XqE4YG5DgFlXwt?p=preview

    <body ng-app="ngAnimate">
    
    Input: 100 > 49
    <br>
    <div ng-hide="100 > 49" > Works properly.</div><br>
    
    Input: '100' > '49'<br>
    <br>
    <div ng-hide="'100' > '49'" > ERROR!</div>
    </body>