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 > |
chevron_right
filter_none
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 > |
chevron_right
filter_none
Output:
Initially:
Incorrect Input:
Correct Input: