Vitor Takara Vitor Takara - 1 month ago 16
HTML Question

AngularJS Changing menu's inside ng-switch-when

Can i put a inside a ng-switch-when?
Here is my code: ( HERE IS A PREVIEW PLNKR LINK)
i want to do something like this:

<div ng-switch-when="Jquery">
<h3>Jquery</h3>

<a class="col-md-1 menu" ng-class="{active: tab == 'Angular'}" ng-click="tab='Angular'"><b>Angular</b></a>

<br /> jQuery is a cross-platform JavaScript library designed to simplify the client-side scripting of HTML. jQuery is the most popular JavaScript library in use today, with installation on 65% of the top 10 million highest-trafficked sites on the
Web. jQuery is free, open-source software licensed under the MIT License.
</div>


Here i have 3 menus, and on second menu (JQUERY), i put a link to menu 1 (ANGULAR), but it does not work... Can anyone help me please?

Thanks a lot!!

Answer

ng-switch creates a new scope... you need to use $parent to access the correct scope to define the tab attribute:

<a class="col-md-1 menu" ng-click="$parent.tab='Angular'"><b>Angular</b></a>

(I removed the class because it was unnecessary here)