AngularJS | angular.equals() Function

The angular.equals() Function in AngularJS is used to compare two objects or two values whether these are same or not. If the two values are same, it returns TRUE else it will return FALSE.

Syntax:

angular.equals(val1, val2)

Where val1 and val2 are the values or the objects to be compared.
Return Value: Returns TRUE or FALSE

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
<head>
 <script src=
 "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js">
 </script>
 <title>angular.equals()</title>
 </head>
  
<body ng-app="app" style="text-align:Center">
  <h1 style="color:green">GeeksforGeeks</h1>
  <h2>angular.equals()</h2>
  
<div ng-controller="geek">
  Input A: <input type="number" ng-model="val1" ng-change="check()" />
  <br /><br>
  Input B: <input type="number" ng-model="val2" ng-change="check()" />
  <br /><br>
  {{msg}}
</div>
  
  <script>
  var app = angular.module("app", []);
  app.controller('geek', ['$scope', function ($scope) {
    $scope.val1 = 0;
    $scope.val2 = 0;
    $scope.check = function () {
      if (angular.equals($scope.val1, $scope.val2))
        $scope.msg = "Input values are equal.";
      else
        $scope.msg = "Input values are not equal.";
      }
    }]);
  
</script>
</body>
</html>

chevron_right


Output:
Before Input:
equals
After Input:
equals

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
<head>
 <script src=
 "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js">
 </script>
 <title>angular.equals()</title>
 </head>
  
 <body ng-app="app" style="text-align:Center">
   <h1 style="color:green">GeeksforGeeks</h1>
   <h2>angular.equals()</h2>
  
<body ng-app="app">
 <div ng-controller="geek">
    Password: <br>
    <input type="password" ng-model="pass" />
    <br><br>
    Confirm  Password: <br>
    <input type="password" ng-model="PASS" ng-change="match()" /><br />
    <p ng-show="isMatch" style="color:green">Password matched</p>
    <p ng-hide="isMatch || PASS==null" style="color:red">
     Password does not match</p>
  </div>
  
<script>
  var app = angular.module("app", []);
  app.controller('geek', ['$scope', function ($scope) {
   $scope.match = function () {
   $scope.isMatch = angular.equals($scope.pass, $scope.PASS);
}
}]);
     
</script>
</body>
</html>

chevron_right


Output:
Initially:
equals
Incorrect Input:
equals
Correct Input:
equals



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.