Angular.js – using angular.equals() function

A simple Angular.js example of checking if values are equal using the AngularJS API.
<!DOCTYPE html>
<html ng-app="testApp">
<head>

<style>

</style>

    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="Tizen Angular.js example"/>

    <title>Tizen Angular.js example</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>

    <script src="js/jquery-2.1.4.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/angular.min.js"></script>
    <script>

        var app = angular.module('testApp', []);

        app.controller('AppController', function($scope) {

            $scope.check = function() {

              $scope.value1 = "Bartholomeo";
              $scope.value2 = "Bartholomeo";
              $scope.pair1 = angular.equals($scope.value1, $scope.value2);

              $scope.value3 = {name: 'Bart', age: 31, height: 184, weight: 90 };
              $scope.value4 = {name: 'Bart', age: 31, height: 184, weight: 80 };
              $scope.pair2 = angular.equals($scope.value3, $scope.value4);

            }

        });

    </script>
</head>
<body>
  <div ng-controller="AppController">
  <br>
    <button id="myButton" ng-click="check()">
      Click this button to check if values are equal or not
    </button>
    <br><br>
    <div ng-show="pair1">
      Is <b>{{ value1 }}</b> equal to <b>{{ value2 }}</b> ? ==> {{ pair1 }}<br><br>
      Is <b>{{ value3 }}</b> equal to <b>{{ value4 }}</b> ? ==> {{ pair2 }}
    </div>
  </div>
</body>

</html>

Responses

0 Replies