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)'
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.
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.
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.
Add to your scope:
$scope.isNumber = angular.isNumber;
and then use:
ng-show="isNumber(10)"
http://jsfiddle.net/88wqe/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With