Open In App

AngularJS angular.equals() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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

Syntax:

angular.equals(val1, val2);

Parameter value:

  • val1 & val2: It specifies the values or the objects that is to be compared.

Return Value: Returns a boolean value ie either TRUE or FALSE.

Example 1: This example illustrates the implementation of the angular.equals() Function in AngularJS, by comparing the values.

HTML




<!DOCTYPE html>
<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>


Output:

 

Example 2: This example illustrates the implementation of the angular.equals() Function in AngularJS, by verifying its value type to authenticate the password.

HTML




<!DOCTYPE html>
<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"> 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>


Output:

 



Last Updated : 01 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads