blenderous blenderous - 5 months ago 24
AngularJS Question

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.

Answer

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>