如何操作导航条引导4崩溃与angularjs?

z9ju0rcb  于 2022-12-03  发布在  Angular
关注(0)|答案(1)|浏览(185)

我的菜单工作正常。但是当我点击背景关闭菜单时,菜单X不断弹出。这是因为当我点击背景时,他不明白现在他是折叠的
基准:

<div ng-controller="mega_menu_controller">
    <nav class="main-menu navbar navbar-expand-lg fixed-top bg-white shadow">
        <div class="container container-lg-fluid">
            <a class="main-menu__logo navbar-brand d-flex align-items-center" href="{{ site.url }}"><span
                        class="icon-logo"></span></a>
            <button class="navbar-toggler collapsed p-0 mb-1" type="button" data-toggle="collapse"
                    data-target="#navbarsMenu" aria-controls="navbarsMenu" aria-expanded="false" aria-label="Toggle navigation" ng-click="toggle_menu(4)" >
                <span class="icon-bar top-bar"></span>
                <span class="icon-bar middle-bar"></span>
                <span class="icon-bar bottom-bar"></span>
            </button>
            <div class="navbar-collapse collapse main-menu__links w-100" id="navbarsMenu">
                {# MENU DESKTOP #}
                <ul class="nav nav-pills mx-auto desktop">
                    <!-- Artigos -->
                    <li class="dropdown menu-large nav-item">
                        <a href="" class="nav-link d-flex align-items-center"
                           ng-click="toggle_menu(1)" ng-class="{'active' : menu[1]}">Artigos
                            de Poupança <span class="icon-arrow-tip-down"></span></a>
                    </li>

Angular 代码:

app.controller('mega_menu_controller', ["$scope", function ($scope) {

    $scope.menu = [];

    $scope.display_background = false;

    $scope.toggle_menu = function (i) {
        $scope.menu.forEach(function (item, index) {
            if (index !== i)
                $scope.menu[index] = false;
        });

        if (i !== -1) {
            $scope.menu[i] = !$scope.menu[i];
            $scope.display_background = $scope.menu[i];
        } else
            $scope.display_background = false;
    }

}]);
balp4ylt

balp4ylt1#

我是这样解决的:

<div class="background-full position-fixed bottom-0 right-0 left-0 d-none" style="z-index:1029;"
     ng-class="{'d-block d-lg-none animated fadeIn faster': display_background && menu[4]}"
     ng-click="toggle_menu(-1)" data-toggle="collapse"
     data-target="#navbarsMenu"  >
</div>

相关问题