Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ng show if the variable is a number

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)'
like image 645
Sebastien Avatar asked Dec 02 '13 09:12

Sebastien


People also ask

How do you check a variable is a number in angular?

The angular. isNumber() function in AngularJS is used to determine the parameter inside isNumber function is a number or not. It returns true if the reference is a number otherwise returns false. Return Value: It returns true if the passed value is a number else false.

What is the difference between Ng-if and Ng-show?

ng-if can only render data whenever the condition is true. It doesn't have any rendered data until the condition is true. ng-show can show and hide the rendered data, that is, it always kept the rendered data and show or hide on the basis of that directives.

What is Div ng-if?

Definition and Usage. The ng-if directive removes the HTML element if the expression evaluates to false. If the if statement evaluates to true, a copy of the Element is added in the DOM.


1 Answers

Add to your scope:

$scope.isNumber = angular.isNumber;

and then use:

ng-show="isNumber(10)"

http://jsfiddle.net/88wqe/

like image 89
CD.. Avatar answered Oct 24 '22 22:10

CD..