Apple Pie Apple Pie - 1 month ago 30
AngularJS Question

Ternary operator on aria-expanded angularjs

I am trying to add aria-expanded to a link, I want the value of aria-expanded to be true when the user has expanded the link and false when it's not. I am not sure how to achieve this, i think a ternary operator would do but not sure how.

<a href="" ng-click="do()" class="" aria-expanded="{{}}" aria-label="test">
<span class=""></span>Something
</a>

Answer

You can simply bind the property to a variable

<a href="" ng-click="do()" class="" aria-expanded="{{expandedValue}}" aria-label="test">
  <span class="">Something</span>
</a>

In your controller

$scope.do = function(){
    $scope.expandedValue = !$scope.expandedValue;
}