angular.Object.equals

Description

Determines if two objects or two values are equivalent. Supports value types, arrays and objects.

Two objects or values are considered equivalent if at least one of the following is true:

During a property comparision, properties of function type and properties with names that begin with $ are ignored.

Note: This function is used to augment the Object type in Angular expressions. See angular.Array for more information about Angular arrays.

Usage

angular.Object.equals(o1, o2);

Parameters

Returns

{boolean}

True if arguments are equal.

Example

    <script>
      function Ctrl() {
        this.master = {
          salutation: 'Hello',
          name: 'world'
        };
        this.greeting = angular.copy(this.master);
      }
    </script>
    <div ng:controller="Ctrl">
      Salutation: <input type="text" ng:model="greeting.salutation"><br/>
      Name: <input type="text" ng:model="greeting.name"><br/>
      <hr/>

      The <code>greeting</code> object is
      <span ng:hide="greeting.$equals(master)">NOT</span> equal to
      <code>{salutation:'Hello', name:'world'}</code>.

      <pre>greeting={{greeting}}</pre>
    </div>
    it('should print that initialy greeting is equal to the hardcoded value object', function() {
      expect(element('.doc-example-live input[ng\\:model="greeting.salutation"]').val()).toBe('Hello');
      expect(element('.doc-example-live input[ng\\:model="greeting.name"]').val()).toBe('world');
      expect(element('.doc-example-live span').css('display')).toBe('none');
    });

    it('should say that the objects are not equal when the form is modified', function() {
      input('greeting.name').enter('kitty');
      expect(element('.doc-example-live span').css('display')).toBe('inline');
    });