Search code examples
angularjsng-class

How to check type of variable inside ng-class?


<div ng-class="{
    'undefined' : typeof object.property === 'undefined',
    'edit-active' : open == true
  }"> 
      {{ object.property }} 
</div>

This gives me a syntax error:

Error: [$parse:syntax] Syntax Error: Token 'object.property' is unexpected, expecting [}]

How can I check if object.property is defined?

Note: I am using angular 1.2.28.


Solution

  • If you need check is there smth, you can do much simplier

    <div ng-class="{
        'undefined' : !object.property,
        'edit-active' :open == true
      }"> 
          {{ object.property }} 
    </div>