Hide expanded sub menu when another one selected












0














And the I want to expand sub menu when user clicks on it with animation:






angular.module('testApp', ['ngAnimate'])
.controller('testController', ['$scope',
function($scope) {
$scope.workshops = [
{ name: "Workshop audience", id: 'audience' },
{ name: "Workshop catalog", id: 'catalog' },
{ name: "Add a workshop", id: 'add_wk' },
{ name: "Add/Edit categories", id: 'add_ctg' },
{ name: "Add/Edit difficulty level", id: 'add_lvl' },
{ name: "Add/Edit a target group", id: 'add_grp' }
];
}
])

.animation('.slide', function() {
var NG_HIDE_CLASS = 'ng-hide';
return {
beforeAddClass: function(element, className, done) {
if (className === NG_HIDE_CLASS) {
element.slideUp(done);
}
},
removeClass: function(element, className, done) {
if (className === NG_HIDE_CLASS) {
element.hide().slideDown(done);
}
}
}
});

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


<div ng-app="testApp" ng-controller="testController">
<ul>
<li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
<a class="nav-link" ng-click="expand = !expand;">Analysis</a>
<ul class="slide" ng-show="expand">
<li>
<a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
</li>
</ul>
</li>
<li ng-class="{ active: isActive('/workshop/') }">
<a ng-click="expand2 = !expand2">Workshop </a>
<ul class="nav flex-column sub-menu slide" ng-show="expand2">
<li data-ng-repeat="workshop in workshops">
<a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
</li>
</ul>
</li>
</ul>
</div>





It works fine. All sub menus are displayed when I click on them, but how can I hide sub menus which are already expanded when I want to open a new one?
Here is fiddle










share|improve this question





























    0














    And the I want to expand sub menu when user clicks on it with animation:






    angular.module('testApp', ['ngAnimate'])
    .controller('testController', ['$scope',
    function($scope) {
    $scope.workshops = [
    { name: "Workshop audience", id: 'audience' },
    { name: "Workshop catalog", id: 'catalog' },
    { name: "Add a workshop", id: 'add_wk' },
    { name: "Add/Edit categories", id: 'add_ctg' },
    { name: "Add/Edit difficulty level", id: 'add_lvl' },
    { name: "Add/Edit a target group", id: 'add_grp' }
    ];
    }
    ])

    .animation('.slide', function() {
    var NG_HIDE_CLASS = 'ng-hide';
    return {
    beforeAddClass: function(element, className, done) {
    if (className === NG_HIDE_CLASS) {
    element.slideUp(done);
    }
    },
    removeClass: function(element, className, done) {
    if (className === NG_HIDE_CLASS) {
    element.hide().slideDown(done);
    }
    }
    }
    });

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


    <div ng-app="testApp" ng-controller="testController">
    <ul>
    <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
    <a class="nav-link" ng-click="expand = !expand;">Analysis</a>
    <ul class="slide" ng-show="expand">
    <li>
    <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
    </li>
    </ul>
    </li>
    <li ng-class="{ active: isActive('/workshop/') }">
    <a ng-click="expand2 = !expand2">Workshop </a>
    <ul class="nav flex-column sub-menu slide" ng-show="expand2">
    <li data-ng-repeat="workshop in workshops">
    <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
    </li>
    </ul>
    </li>
    </ul>
    </div>





    It works fine. All sub menus are displayed when I click on them, but how can I hide sub menus which are already expanded when I want to open a new one?
    Here is fiddle










    share|improve this question



























      0












      0








      0







      And the I want to expand sub menu when user clicks on it with animation:






      angular.module('testApp', ['ngAnimate'])
      .controller('testController', ['$scope',
      function($scope) {
      $scope.workshops = [
      { name: "Workshop audience", id: 'audience' },
      { name: "Workshop catalog", id: 'catalog' },
      { name: "Add a workshop", id: 'add_wk' },
      { name: "Add/Edit categories", id: 'add_ctg' },
      { name: "Add/Edit difficulty level", id: 'add_lvl' },
      { name: "Add/Edit a target group", id: 'add_grp' }
      ];
      }
      ])

      .animation('.slide', function() {
      var NG_HIDE_CLASS = 'ng-hide';
      return {
      beforeAddClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.slideUp(done);
      }
      },
      removeClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.hide().slideDown(done);
      }
      }
      }
      });

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


      <div ng-app="testApp" ng-controller="testController">
      <ul>
      <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
      <a class="nav-link" ng-click="expand = !expand;">Analysis</a>
      <ul class="slide" ng-show="expand">
      <li>
      <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
      </li>
      </ul>
      </li>
      <li ng-class="{ active: isActive('/workshop/') }">
      <a ng-click="expand2 = !expand2">Workshop </a>
      <ul class="nav flex-column sub-menu slide" ng-show="expand2">
      <li data-ng-repeat="workshop in workshops">
      <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
      </li>
      </ul>
      </li>
      </ul>
      </div>





      It works fine. All sub menus are displayed when I click on them, but how can I hide sub menus which are already expanded when I want to open a new one?
      Here is fiddle










      share|improve this question















      And the I want to expand sub menu when user clicks on it with animation:






      angular.module('testApp', ['ngAnimate'])
      .controller('testController', ['$scope',
      function($scope) {
      $scope.workshops = [
      { name: "Workshop audience", id: 'audience' },
      { name: "Workshop catalog", id: 'catalog' },
      { name: "Add a workshop", id: 'add_wk' },
      { name: "Add/Edit categories", id: 'add_ctg' },
      { name: "Add/Edit difficulty level", id: 'add_lvl' },
      { name: "Add/Edit a target group", id: 'add_grp' }
      ];
      }
      ])

      .animation('.slide', function() {
      var NG_HIDE_CLASS = 'ng-hide';
      return {
      beforeAddClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.slideUp(done);
      }
      },
      removeClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.hide().slideDown(done);
      }
      }
      }
      });

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


      <div ng-app="testApp" ng-controller="testController">
      <ul>
      <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
      <a class="nav-link" ng-click="expand = !expand;">Analysis</a>
      <ul class="slide" ng-show="expand">
      <li>
      <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
      </li>
      </ul>
      </li>
      <li ng-class="{ active: isActive('/workshop/') }">
      <a ng-click="expand2 = !expand2">Workshop </a>
      <ul class="nav flex-column sub-menu slide" ng-show="expand2">
      <li data-ng-repeat="workshop in workshops">
      <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
      </li>
      </ul>
      </li>
      </ul>
      </div>





      It works fine. All sub menus are displayed when I click on them, but how can I hide sub menus which are already expanded when I want to open a new one?
      Here is fiddle






      angular.module('testApp', ['ngAnimate'])
      .controller('testController', ['$scope',
      function($scope) {
      $scope.workshops = [
      { name: "Workshop audience", id: 'audience' },
      { name: "Workshop catalog", id: 'catalog' },
      { name: "Add a workshop", id: 'add_wk' },
      { name: "Add/Edit categories", id: 'add_ctg' },
      { name: "Add/Edit difficulty level", id: 'add_lvl' },
      { name: "Add/Edit a target group", id: 'add_grp' }
      ];
      }
      ])

      .animation('.slide', function() {
      var NG_HIDE_CLASS = 'ng-hide';
      return {
      beforeAddClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.slideUp(done);
      }
      },
      removeClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.hide().slideDown(done);
      }
      }
      }
      });

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


      <div ng-app="testApp" ng-controller="testController">
      <ul>
      <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
      <a class="nav-link" ng-click="expand = !expand;">Analysis</a>
      <ul class="slide" ng-show="expand">
      <li>
      <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
      </li>
      </ul>
      </li>
      <li ng-class="{ active: isActive('/workshop/') }">
      <a ng-click="expand2 = !expand2">Workshop </a>
      <ul class="nav flex-column sub-menu slide" ng-show="expand2">
      <li data-ng-repeat="workshop in workshops">
      <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
      </li>
      </ul>
      </li>
      </ul>
      </div>





      angular.module('testApp', ['ngAnimate'])
      .controller('testController', ['$scope',
      function($scope) {
      $scope.workshops = [
      { name: "Workshop audience", id: 'audience' },
      { name: "Workshop catalog", id: 'catalog' },
      { name: "Add a workshop", id: 'add_wk' },
      { name: "Add/Edit categories", id: 'add_ctg' },
      { name: "Add/Edit difficulty level", id: 'add_lvl' },
      { name: "Add/Edit a target group", id: 'add_grp' }
      ];
      }
      ])

      .animation('.slide', function() {
      var NG_HIDE_CLASS = 'ng-hide';
      return {
      beforeAddClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.slideUp(done);
      }
      },
      removeClass: function(element, className, done) {
      if (className === NG_HIDE_CLASS) {
      element.hide().slideDown(done);
      }
      }
      }
      });

      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


      <div ng-app="testApp" ng-controller="testController">
      <ul>
      <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
      <a class="nav-link" ng-click="expand = !expand;">Analysis</a>
      <ul class="slide" ng-show="expand">
      <li>
      <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
      </li>
      </ul>
      </li>
      <li ng-class="{ active: isActive('/workshop/') }">
      <a ng-click="expand2 = !expand2">Workshop </a>
      <ul class="nav flex-column sub-menu slide" ng-show="expand2">
      <li data-ng-repeat="workshop in workshops">
      <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
      </li>
      </ul>
      </li>
      </ul>
      </div>






      angularjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 9:03









      Akber Iqbal

      1,7812720




      1,7812720










      asked Nov 13 '18 at 8:45









      Yevgeniy BagackiyYevgeniy Bagackiy

      508419




      508419
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Does this work?






          angular.module('testApp', ['ngAnimate'])
          .controller('testController', ['$scope',
          function($scope) {
          $scope.workshops = [
          { name: "Workshop audience", id: 'audience' },
          { name: "Workshop catalog", id: 'catalog' },
          { name: "Add a workshop", id: 'add_wk' },
          { name: "Add/Edit categories", id: 'add_ctg' },
          { name: "Add/Edit difficulty level", id: 'add_lvl' },
          { name: "Add/Edit a target group", id: 'add_grp' }
          ];

          $scope.expandToggle= function(subMenu){
          if (subMenu == 'expand'){
          $scope.expand = !$scope.expand;
          if($scope.expand2){$scope.expand2 = false;}
          }
          if (subMenu == 'expand2'){
          $scope.expand2 = !$scope.expand2;
          if($scope.expand){$scope.expand = false;}
          }
          }

          }
          ])

          .animation('.slide', function() {
          var NG_HIDE_CLASS = 'ng-hide';
          return {
          beforeAddClass: function(element, className, done) {
          if (className === NG_HIDE_CLASS) {
          element.slideUp(done);
          }
          },
          removeClass: function(element, className, done) {
          if (className === NG_HIDE_CLASS) {
          element.hide().slideDown(done);
          }
          }
          }
          });

          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
          <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
          <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


          <div ng-app="testApp" ng-controller="testController">
          <ul>
          <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
          <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
          <ul class="slide" ng-show="expand">
          <li>
          <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
          </li>
          </ul>
          </li>
          <li ng-class="{ active: isActive('/workshop/') }">
          <a ng-click="expandToggle('expand2')">Workshop </a>
          <ul class="nav flex-column sub-menu slide" ng-show="expand2">
          <li data-ng-repeat="workshop in workshops">
          <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
          </li>
          </ul>
          </li>
          </ul>
          </div>








          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277007%2fhide-expanded-sub-menu-when-another-one-selected%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Does this work?






            angular.module('testApp', ['ngAnimate'])
            .controller('testController', ['$scope',
            function($scope) {
            $scope.workshops = [
            { name: "Workshop audience", id: 'audience' },
            { name: "Workshop catalog", id: 'catalog' },
            { name: "Add a workshop", id: 'add_wk' },
            { name: "Add/Edit categories", id: 'add_ctg' },
            { name: "Add/Edit difficulty level", id: 'add_lvl' },
            { name: "Add/Edit a target group", id: 'add_grp' }
            ];

            $scope.expandToggle= function(subMenu){
            if (subMenu == 'expand'){
            $scope.expand = !$scope.expand;
            if($scope.expand2){$scope.expand2 = false;}
            }
            if (subMenu == 'expand2'){
            $scope.expand2 = !$scope.expand2;
            if($scope.expand){$scope.expand = false;}
            }
            }

            }
            ])

            .animation('.slide', function() {
            var NG_HIDE_CLASS = 'ng-hide';
            return {
            beforeAddClass: function(element, className, done) {
            if (className === NG_HIDE_CLASS) {
            element.slideUp(done);
            }
            },
            removeClass: function(element, className, done) {
            if (className === NG_HIDE_CLASS) {
            element.hide().slideDown(done);
            }
            }
            }
            });

            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


            <div ng-app="testApp" ng-controller="testController">
            <ul>
            <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
            <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
            <ul class="slide" ng-show="expand">
            <li>
            <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
            </li>
            </ul>
            </li>
            <li ng-class="{ active: isActive('/workshop/') }">
            <a ng-click="expandToggle('expand2')">Workshop </a>
            <ul class="nav flex-column sub-menu slide" ng-show="expand2">
            <li data-ng-repeat="workshop in workshops">
            <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
            </li>
            </ul>
            </li>
            </ul>
            </div>








            share|improve this answer


























              1














              Does this work?






              angular.module('testApp', ['ngAnimate'])
              .controller('testController', ['$scope',
              function($scope) {
              $scope.workshops = [
              { name: "Workshop audience", id: 'audience' },
              { name: "Workshop catalog", id: 'catalog' },
              { name: "Add a workshop", id: 'add_wk' },
              { name: "Add/Edit categories", id: 'add_ctg' },
              { name: "Add/Edit difficulty level", id: 'add_lvl' },
              { name: "Add/Edit a target group", id: 'add_grp' }
              ];

              $scope.expandToggle= function(subMenu){
              if (subMenu == 'expand'){
              $scope.expand = !$scope.expand;
              if($scope.expand2){$scope.expand2 = false;}
              }
              if (subMenu == 'expand2'){
              $scope.expand2 = !$scope.expand2;
              if($scope.expand){$scope.expand = false;}
              }
              }

              }
              ])

              .animation('.slide', function() {
              var NG_HIDE_CLASS = 'ng-hide';
              return {
              beforeAddClass: function(element, className, done) {
              if (className === NG_HIDE_CLASS) {
              element.slideUp(done);
              }
              },
              removeClass: function(element, className, done) {
              if (className === NG_HIDE_CLASS) {
              element.hide().slideDown(done);
              }
              }
              }
              });

              <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
              <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
              <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


              <div ng-app="testApp" ng-controller="testController">
              <ul>
              <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
              <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
              <ul class="slide" ng-show="expand">
              <li>
              <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
              </li>
              </ul>
              </li>
              <li ng-class="{ active: isActive('/workshop/') }">
              <a ng-click="expandToggle('expand2')">Workshop </a>
              <ul class="nav flex-column sub-menu slide" ng-show="expand2">
              <li data-ng-repeat="workshop in workshops">
              <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
              </li>
              </ul>
              </li>
              </ul>
              </div>








              share|improve this answer
























                1












                1








                1






                Does this work?






                angular.module('testApp', ['ngAnimate'])
                .controller('testController', ['$scope',
                function($scope) {
                $scope.workshops = [
                { name: "Workshop audience", id: 'audience' },
                { name: "Workshop catalog", id: 'catalog' },
                { name: "Add a workshop", id: 'add_wk' },
                { name: "Add/Edit categories", id: 'add_ctg' },
                { name: "Add/Edit difficulty level", id: 'add_lvl' },
                { name: "Add/Edit a target group", id: 'add_grp' }
                ];

                $scope.expandToggle= function(subMenu){
                if (subMenu == 'expand'){
                $scope.expand = !$scope.expand;
                if($scope.expand2){$scope.expand2 = false;}
                }
                if (subMenu == 'expand2'){
                $scope.expand2 = !$scope.expand2;
                if($scope.expand){$scope.expand = false;}
                }
                }

                }
                ])

                .animation('.slide', function() {
                var NG_HIDE_CLASS = 'ng-hide';
                return {
                beforeAddClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.slideUp(done);
                }
                },
                removeClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.hide().slideDown(done);
                }
                }
                }
                });

                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


                <div ng-app="testApp" ng-controller="testController">
                <ul>
                <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
                <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
                <ul class="slide" ng-show="expand">
                <li>
                <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
                </li>
                </ul>
                </li>
                <li ng-class="{ active: isActive('/workshop/') }">
                <a ng-click="expandToggle('expand2')">Workshop </a>
                <ul class="nav flex-column sub-menu slide" ng-show="expand2">
                <li data-ng-repeat="workshop in workshops">
                <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
                </li>
                </ul>
                </li>
                </ul>
                </div>








                share|improve this answer












                Does this work?






                angular.module('testApp', ['ngAnimate'])
                .controller('testController', ['$scope',
                function($scope) {
                $scope.workshops = [
                { name: "Workshop audience", id: 'audience' },
                { name: "Workshop catalog", id: 'catalog' },
                { name: "Add a workshop", id: 'add_wk' },
                { name: "Add/Edit categories", id: 'add_ctg' },
                { name: "Add/Edit difficulty level", id: 'add_lvl' },
                { name: "Add/Edit a target group", id: 'add_grp' }
                ];

                $scope.expandToggle= function(subMenu){
                if (subMenu == 'expand'){
                $scope.expand = !$scope.expand;
                if($scope.expand2){$scope.expand2 = false;}
                }
                if (subMenu == 'expand2'){
                $scope.expand2 = !$scope.expand2;
                if($scope.expand){$scope.expand = false;}
                }
                }

                }
                ])

                .animation('.slide', function() {
                var NG_HIDE_CLASS = 'ng-hide';
                return {
                beforeAddClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.slideUp(done);
                }
                },
                removeClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.hide().slideDown(done);
                }
                }
                }
                });

                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


                <div ng-app="testApp" ng-controller="testController">
                <ul>
                <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
                <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
                <ul class="slide" ng-show="expand">
                <li>
                <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
                </li>
                </ul>
                </li>
                <li ng-class="{ active: isActive('/workshop/') }">
                <a ng-click="expandToggle('expand2')">Workshop </a>
                <ul class="nav flex-column sub-menu slide" ng-show="expand2">
                <li data-ng-repeat="workshop in workshops">
                <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
                </li>
                </ul>
                </li>
                </ul>
                </div>








                angular.module('testApp', ['ngAnimate'])
                .controller('testController', ['$scope',
                function($scope) {
                $scope.workshops = [
                { name: "Workshop audience", id: 'audience' },
                { name: "Workshop catalog", id: 'catalog' },
                { name: "Add a workshop", id: 'add_wk' },
                { name: "Add/Edit categories", id: 'add_ctg' },
                { name: "Add/Edit difficulty level", id: 'add_lvl' },
                { name: "Add/Edit a target group", id: 'add_grp' }
                ];

                $scope.expandToggle= function(subMenu){
                if (subMenu == 'expand'){
                $scope.expand = !$scope.expand;
                if($scope.expand2){$scope.expand2 = false;}
                }
                if (subMenu == 'expand2'){
                $scope.expand2 = !$scope.expand2;
                if($scope.expand){$scope.expand = false;}
                }
                }

                }
                ])

                .animation('.slide', function() {
                var NG_HIDE_CLASS = 'ng-hide';
                return {
                beforeAddClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.slideUp(done);
                }
                },
                removeClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.hide().slideDown(done);
                }
                }
                }
                });

                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


                <div ng-app="testApp" ng-controller="testController">
                <ul>
                <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
                <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
                <ul class="slide" ng-show="expand">
                <li>
                <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
                </li>
                </ul>
                </li>
                <li ng-class="{ active: isActive('/workshop/') }">
                <a ng-click="expandToggle('expand2')">Workshop </a>
                <ul class="nav flex-column sub-menu slide" ng-show="expand2">
                <li data-ng-repeat="workshop in workshops">
                <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
                </li>
                </ul>
                </li>
                </ul>
                </div>





                angular.module('testApp', ['ngAnimate'])
                .controller('testController', ['$scope',
                function($scope) {
                $scope.workshops = [
                { name: "Workshop audience", id: 'audience' },
                { name: "Workshop catalog", id: 'catalog' },
                { name: "Add a workshop", id: 'add_wk' },
                { name: "Add/Edit categories", id: 'add_ctg' },
                { name: "Add/Edit difficulty level", id: 'add_lvl' },
                { name: "Add/Edit a target group", id: 'add_grp' }
                ];

                $scope.expandToggle= function(subMenu){
                if (subMenu == 'expand'){
                $scope.expand = !$scope.expand;
                if($scope.expand2){$scope.expand2 = false;}
                }
                if (subMenu == 'expand2'){
                $scope.expand2 = !$scope.expand2;
                if($scope.expand){$scope.expand = false;}
                }
                }

                }
                ])

                .animation('.slide', function() {
                var NG_HIDE_CLASS = 'ng-hide';
                return {
                beforeAddClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.slideUp(done);
                }
                },
                removeClass: function(element, className, done) {
                if (className === NG_HIDE_CLASS) {
                element.hide().slideDown(done);
                }
                }
                }
                });

                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-animate.js"></script>


                <div ng-app="testApp" ng-controller="testController">
                <ul>
                <li class="nav-item" ng-class="{ active: isActive('/analysis/recommendation') }">
                <a class="nav-link" ng-click="expandToggle('expand')">Analysis</a>
                <ul class="slide" ng-show="expand">
                <li>
                <a ng-class="{active:isActive('/analysis/recommendation')}" href="#!analysis/recommendation">Recommendation</a>
                </li>
                </ul>
                </li>
                <li ng-class="{ active: isActive('/workshop/') }">
                <a ng-click="expandToggle('expand2')">Workshop </a>
                <ul class="nav flex-column sub-menu slide" ng-show="expand2">
                <li data-ng-repeat="workshop in workshops">
                <a href="#!workshop/{{workshop.id}}" ng-class="{active:isActive('/workshop/'+workshop.id)}" ng-bind="workshop.name"></a>
                </li>
                </ul>
                </li>
                </ul>
                </div>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 9:10









                Akber IqbalAkber Iqbal

                1,7812720




                1,7812720






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277007%2fhide-expanded-sub-menu-when-another-one-selected%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine