I've made a dropdown menu using angularJS, it works fine but I feel that I'm not following the DRY principle. Is there a way to combine this switch statement into something more efficient with less code? Instead of having 3 "cases" can I just use an OR operator inside of a data-ng-switch-when
or something like that? This code will get bigger because it's quite a big project so code efficiency is key.
<ul id="main-menu">
<li data-ng-repeat="item in mainMenu" data-ng-switch on="item"><a href="{{item}}.php">{{item}}</a>
<ul data-ng-switch-when="Meddelanden">
<li data-ng-repeat="subitem in subMenu.messages"><a href="{{subitem}}.php">{{subitem}}</a></li>
</ul>
<ul data-ng-switch-when="Mina sidor">
<li data-ng-repeat="subitem in subMenu.myPages"><a href="{{subitem}}.php">{{subitem}}</a></li>
</ul>
<ul data-ng-switch-when="Verktyg">
<li data-ng-repeat="subitem in subMenu.tools"><a href="{{subitem}}.php">{{subitem}}</a></li>
</ul>
</li>
</ul>
Here's my controller containing the menu items:
onlinePlatform.controller('onlinePlatformCtrl', function ($scope) {
$scope.mainMenu = ['Startsida', 'Nyheter', 'Meddelanden', 'Mina sidor', 'Forum', 'Kalender', 'Verktyg', 'Hjälp'],
$scope.subMenu = {
messages: ['Inkorg', 'Skickat', 'Borttaget'],
myPages: ['Mina kurser', 'Mitt schema', 'Klasslista', 'Anteckningar'],
tools: ['Ladda ner Dreamspark produkter']
}
});