I want to display an element only if a value is a number. How to do this? I tried :
ng-show='angular.isNumber(10)'
ng-show='isNumber(10)'
I want to display an element only if a value is a number. How to do this? I tried :
ng-show='angular.isNumber(10)'
ng-show='isNumber(10)'
Add to your scope:
$scope.isNumber = angular.isNumber;
and then use:
ng-show="isNumber(10)"
<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)'