Ng show if the variable is a number

我们两清 提交于 2019-12-05 01:33:39

Add to your scope:

$scope.isNumber = angular.isNumber;

and then use:

ng-show="isNumber(10)"

http://jsfiddle.net/88wqe/

eddiec
<div ng-controller="Ctrl" ng-show="isNumber(num)">
    AAA
</div>

function Ctrl($scope){
    $scope.num = '10';

    $scope.isNumber= function (n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    }
}

Here's a JS Fiddle http://jsfiddle.net/7RD47/

It uses the top answer from Validate decimal numbers in JavaScript - IsNumeric(), which is a more complete way of validating numbers.

Try this:

ng-show='isNumeric(10)'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!