user3346088
user3346088

Reputation: 109

if else angular ng-class not working

this is in my ng-repeat, so I want if lp-image is not zero, apply class col-md-8 and else apply col-md-12 if it's zero. The result is strange, it returned col-md-12.

ng-class="{'col-md-8':item.lp-image != 0, 'col-md-12':item.lp-image == 0}">

Upvotes: 0

Views: 586

Answers (2)

Jay Shukla
Jay Shukla

Reputation: 5826

Try this

ng-class="{'col-md-8':item['lp-image'] != 0, 'col-md-12':item['lp-image'] == 0}">

Upvotes: 1

Mikke
Mikke

Reputation: 2167

Your variable name cannot contain a hyphen -, it's parsed as a minus operator. Use JavaScript's naming convention of camelCase, i.e. item.lpImage.

Upvotes: 1

Related Questions