3

I am doing like this

 <div class="tiles" ng-repeat="stat in states" ng-click="select(stat)" ng-class="{active: isActive(stat)}">
    ....
    </div>

//controller

$scope.select= function(item) {
    $scope.selected = item; 
};

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

};

clicking on tiles it is adding active class and clicking on other tiles removing from first tiles and adding to another tiles.It is working as expected .But what i am trying to achieve is clicking on same tiles again i have to remove active class ,clicking on again i have to add like toggling .But no idea how to achieve this .Please help

2 Answers 2

3

Update your select function to set the selected property to null if it's already selected:

$scope.select = function(item) {
    $scope.selected = ($scope.selected === item ? null : item); 
};

JSFiddle Example

http://jsfiddle.net/bATZ5/

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

Comments

2

just change your code to this:

$scope.select= function(item) {
    if (item === $scope.selected) {
        $scope.selected = null;
    } else {
        $scope.selected = item;
    }

};

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.