ng-switch inside ng-repeat Angularjs

3.3k Views Asked by At

i have question how to use ng-switch inside ng-repeat and use scope for switch-on ?

example :

 <div ng-repeat="item in submenu">
            <div class="animate-switch"  ng-switch-when="{{item.filter}}">
                <div class="navbar navbar-default navbar-static-top {{item.filter}}">
                    <div  class="navbar-collapse collapse" id="navbar-{{item.filter}}">
                        <ul class="nav navbar-nav subnav">
                            <li ng-repeat="subitem in item.sub" class="items"  >
                                <a ng-href="{{subitem.link}}" class="{{selected }}" ng-click="selectfiltersub(subitem.filter)">{{item.name}}</a>
                            </li>
                        </ul>
                    </div>

                </div>
            </div>
        </div>

$scope.submenu :

 $scope.submenu =[{
            name:'Glasba',
            filter:'music',
            sub:[{
                name:'Koncerti',
                filter:'Concerts'
            },{
                name:'Klasika',
                filter:'Clasic'
            },{
                name:'Elektronika',
                filter:'Elektro'
            },{
                name:'Indy',
                filter:'Indy'
            },{
                name:'Teater',
                filter:'Theater'
            }]
        }]

so the problem is on ng-switch-when = "{{item.filter}}" <-- does not recognize. the output is the same as code ng-swith-when="{{item.filter}}" insted of music. What can i do ? thx for anwsers !

exmaple picture enter image description here <--upper is menu and udner 50px height is submenu with no content now ...

1

There are 1 best solutions below

6
On BEST ANSWER

From ng-switch documentation:

Be aware that the attribute values to match against cannot be expressions. They are interpreted as literal string values to match against. For example, ng-switch-when="someVal" will match against the string "someVal" not against the value of the expression $scope.someVal.

Look into using ng-if instead:

<div class="animate-switch"  ng-if="item.filter === 'music'">
  filter equals 'music'
</div>