Tutorialsplane

angular.equals


angular.equals- This is used to check if two objects or two values are equal. It supports the value types, regular expressions, arrays and objects. Here in this tutorial we are going to explain how you can use this function to compare the two values, objects or arrays. You can use our online demo try and edit the code online.


angular.equals | compare strings | Array | Objects | Example

Two values or objects will be equal if one of the following condition is satisfied :

Syntax

Syntax for angular equals is –

AngularJs compare strings | Array | Objects :

angular.equals(object1, object2);

Agruments

Return

This will retrun true or false on the basis of comparision.

angular.equals Example

Let us create a simple example to compare two strings using this function –

Compare two Strings in AngularJs Example:




 
 

  
<div ng-app="myApp">  
<div ng-controller="myController">  
    Value 1 <br/>
	Value 2 <br/>
	
    <button ng-click="compareValues()">Compare Values</button>
	<br/>
	Result = {{result}}
	
</div> 
</div>
  

Try it »

If you run the above example it will produce the output something like this –

Compare two Objects in AngularJs Example:

You can compare two objects in angularjs as below –

Compare two Strings in AngularJs Example:




 
 

  
<div ng-app="myApp">  
<div ng-controller="myController">  
    <b>User 1</b>
    Name <br/>
	Phone <br/>
	<b>User 1</b>
    Name <br/>
	Phone <br/>
	
    <button ng-click="compareObjs()">Compare Values</button>
	<br/>
	Result = {{result}}
	
</div> 
</div>
  

Try it »

AngularJs Api Refrence

AngularJs Directive