user4199699 user4199699 - 3 months ago 20
AngularJS Question

Angular JS ternary operator inside div tag

Am using a div condition as shown below

<div data-index="5" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 tiles ${ {{myvariable.data}} ? 'hidden-lg hidden-md hidden-xs hidden-sm':''}" data-myapp-detail="somexyz">


Where the
{{myvariable.data}}
is giving problem when it is becomes "false".
is there any angular js condition that i can initiate a variable based on the
{{myvariable.data}}
and use that variable in div tag ternary condition.

Where as if i keep boolean value false directly instead of
{{myvariable.data}}
it works as expected.

<div data-index="5" class="col-xs-12 col-sm-4 col-md-3 col-lg-2 tiles ${ false ? 'hidden-lg hidden-md hidden-xs hidden-sm':''}" data-myapp-detail="somexyz">

Answer

For Angular2

<div data-index="5" 
  class="col-xs-12 col-sm-4 col-md-3 col-lg-2 tiles"
  [ngClass]="myvariable.data ? 'hidden-lg hidden-md hidden-xs hidden-sm':''" 
  data-myapp-detail="somexyz">

or

<div data-index="5" 
  class="col-xs-12 col-sm-4 col-md-3 col-lg-2 tiles"
  [ngClass]="myvariable.data ? ['hidden-lg', 'hidden-md', 'hidden-xs', 'hidden-sm']:''" 
  data-myapp-detail="somexyz">
Comments