None
None

Reputation: 9247

How to add class on ng-click?

I have this: http://plnkr.co/edit/gJko3umteXXEye7o9StR?p=preview

How can i add class "active-link" on:

@Translate("PERSONAL_INFORMATION") 
@Translate("NOTIFICATIONS") 
@Translate("CHANGE_PASSWORD") 
@Translate("GAME_SETTINGS")

Upvotes: 2

Views: 2274

Answers (2)

Kalhan.Toress
Kalhan.Toress

Reputation: 21911

If your using classes like active-link, x-y which have dash (-) then you have to wrap it in ' as below.

ng-class="{'active-link' : activeLink==='PersonalInfo'}" 

if your classes like activeLink which are doesn't have dash (-) then you can avoid from ' but not a must.

ng-class="{activeLink : activeLink==='PersonalInfo'}" 

here is the updated DEMO

Upvotes: 4

brennerm
brennerm

Reputation: 73

Add an ng-class to your element

<div ng-click="setClass()" ng-class="class">@Translate("NOTIFICATIONS")</div>

and change the value in your function

$scope.setClass(new function(){
    $scope.class = "active-link";
})

Upvotes: 1

Related Questions