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:
<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:
Before Input:

After Input:

Example 2:
<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> |
Output:
Initially:

Incorrect Input:

Correct Input:

Recommended Posts:
- AngularJS | angular.isElement() Function
- AngularJS | angular.isFunction() Function
- AngularJS | angular.element() Function
- AngularJS | angular.bootstrap() Function
- AngularJS | angular.lowercase() Function
- AngularJS | angular.bind() Function
- AngularJS | angular.isArray() Function
- AngularJS | angular.toJson() Function
- AngularJS | angular.uppercase() Function
- AngularJS | angular.isString() Function
- AngularJS | angular.isNumber() Function
- AngularJS | angular.isUndefined() Function
- AngularJS | angular.isObject() Function
- AngularJS | angular.isDefined() Function
- AngularJS | angular.isDate() Function
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.



