0

My html

<li data-ng-click="sortCategory('demographics')">Demographics</li>
<li data-ng-click="sortCategory('historical')">Historical</li>
<li data-ng-click="sortCategory('experimental')">Experimental</li>

I tried

<li data-ng-click="sortCategory('socialmedia'); select(item)" data-ng-class="{active: isActive(item)}">Social Media</li>

$scope.isActive = function (item) 
     {
return $scope.isActive(item);
     }

css (less)

li{
&.active {
  background:#0088cc;
}
}

It is not working...

2

1 Answer 1

2

Fully agree with Yoshi you can store the category in a scope variable when calling the sortCategory function and use this to check if a categrory is active or not. A working piece of code could be :

 $scope.category = 'demographics'; //Your default category
 $scope.sortCategory = function (category) {
   $scope.category = category; //Update the category
   ....
 }

 $scope.isActive = function (category) {
   //Check if category of a given <li> is equal to the current category
   return $scope.category === category;
 }

and a template markup that s look like

<li data-ng-click="sortCategory('demographics')" ng-class="{'active' : isActive('demographics')}">Demographics</li>
<li data-ng-click="sortCategory('historical')" ng-class="{'active' : isActive('historical')}">Historical</li> 

You can find a live example here http://jsfiddle.net/sWKL5/2/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.