Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make less than or greater than comparison in angularjs

Tags:

angularjs

Please anybody explain how to do below check in angularjs

<div ng-show="{{offset <= 10}}">Show Me</div>

If i run it like this it breaks the html, i think due to "<" than in comparison

like image 624
Yashpal Singla Avatar asked Aug 23 '13 13:08

Yashpal Singla


People also ask

What is the difference between greater than and less than in JavaScript?

The greater than operator (>) returns TRUE if the first value is greater than the second value. The less than operator (<) returns TRUE if the first value is less than the second value.

How do you use greater than and less than in Excel?

Greater than and Less than in Excel to Compare Cell Values We can use the greater than and less than conditional operators between two cell values to compare them. Most of the time, conditional operators are used to compare numbers. The greater than operator (>) returns TRUE if the first value is greater than the second value.

Is it possible to use the 'greater than' comparator in an ng-if in HTML?

Is it possible to use the 'greater than' comparator in an ng-if in HTML? The problem is that the ">" symbol prematurely closes the HTML tag. is read as: <div ng-if="foo"> (0 class="bar"> HTML STUFF) </div>

What happens when you compare data of different types in JavaScript?

Comparing data of different types may give unexpected results. When comparing a string with a number, JavaScript will convert the string to a number when doing the comparison. An empty string converts to 0.


2 Answers

Don't use {{}}s:

<div ng-show="offset <= 10">Show Me</div>

The expression given to ng-show is evaluated against the current scope, so there is no need for interpolation – the {{}}s.

You would need the {{}}s if you wanted to do something like this:

<div>Offset is <= 10: {{offset <= 10}}</div>
like image 154
Mark Rajcok Avatar answered Oct 11 '22 19:10

Mark Rajcok


You can also try this, it works!

<!DOCTYPE html>
 <html>
  <script  src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
  </script>
 <body>
  <div  ng-app="">
    10&lt;20 : {{10&lt;20}}
  </div>
 </body>
</html>
like image 33
Sanu Joseph Avatar answered Oct 11 '22 17:10

Sanu Joseph