0

I'm alternating between two windows in angularjs using ng-click and ng-show :

<div ng-init="showTab2 = false">
            <a ng-click="showTab2 = true; showTab1 = false ">#Tab1 </a>
        </div>
 <div ng-init="showTab2 = true">
            <a ng-click="showTab1 = true; showTab2 = false">#Tab2</a>
        </div>

then with ng-show they appear

Could you please tell me how I can change the color of the tab selected ?

Thank you

3
  • 1
    This could help you codepen.io/DesignyourCode/pen/pECjv Commented Jun 1, 2016 at 14:16
  • Have you checked my answer? Commented Jun 1, 2016 at 16:57
  • @User2 thank you for the detailed answer, it worked with ng-class but I couldn't use ng-switch because it creates an other $scope Commented Jun 2, 2016 at 7:30

2 Answers 2

1

I'm not sure how your ng-show fits here but use ng-class to toggle css:

<a ng-class = "{'some-class': showTab1}" 
  ng-click="showTab1 = true; showTab2 = false">#Tab1</a>
Sign up to request clarification or add additional context in comments.

1 Comment

it generates an error in the IDE "expression expected"
1

Please check working example here: Example

JS

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
    $scope.showTab = 1; //If you want to select default tab
});

HTML

<div>
    <a ng-click="showTab = 1" ng-class="{'active': showTab == 1}">#Tab1 </a>
</div>
<div>
   <a ng-click="showTab = 2"  ng-class="{'active': showTab == 2}">#Tab2</a>
</div>

<div ng-switch="showTab">
    <span ng-switch-when="1">Tab1</span>
    <span ng-switch-when="2">Tab2</span>
</div>

CSS

.active {
   color: red;
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.