I have this div somewhere in my code.
<div ng-class="className" >{{className}}</div>
At some point I am calling changeClass
function from an ng-click to change the class of this div.
$scope.changeClass = function(){
console.log($scope.className)
if ($scope.className === "expand-icon")
$scope.className = "expand-icon.expanded";
else
$scope.className = "expand-icon";
};
I can see the class changes because of the console.log and also the {{className}} is outputed on the page. However the css class doesn't seem to be applied.
It's in fact a '+' sign that needs to turn into a '-' with an animation. Here's the css:
/* + button */
.expand-icon {
height: 32px;
width: 32px;
position: relative;
}
.expand-icon::before, .expand-icon::after {
content: " ";
width: 32px;
height: 6px;
background-color: #fff;
display: block;
position: absolute;
top: 50%;
left: 50%;
transition: all 0.15s cubic-bezier(.42, 0, .58, 1);
opacity: 1;
border-radius: 2px;
}
.expand-icon::before {
transform: translate(-50%, -50%) rotate(90deg);
}
.expand-icon::after {
transform: translate(-50%, -50%);
}
.expand-icon {
height: 32px;
width: 32px;
position: relative;
}
.expand-icon.expanded::before {
transform: translate(-50%, -50%) rotate(0deg);
}
.expand-icon.expanded::after {
transform: translate(-50%, -50%) rotate(-90deg);
opacity: 0;
}
So the expand-icon is applied but expand-icon.expanded doesn't have any affect since I'm using this ng-class trick. Any idea why?