Nicoleta Wilskon
Nicoleta Wilskon

Reputation: 697

how to handle conditional ng-class

I have a html format like this , when sec.newValue is not empty I want it to be displayed bold and if its empty , I want to display as it is. so how can I achieve this using ng-class,i tried giving fontweight : bold but it doesn't work

<label class="message">
<span ng-repeat="sec in error" ng-class="{secNew?!sec.newValue }">{{sec. error}}</span>
</label>
.secNew {
 font-weight: bold;
}

Upvotes: 0

Views: 36

Answers (1)

baao
baao

Reputation: 73301

You pass an object whose key is the class to add, and the value is the condition which, when true, makes the class to actually be attached

{secNew: sec.newValue}

will apply class secNew only if sec.newValue returns something truthy.

Upvotes: 2

Related Questions