简体   繁体   English

为什么ng-include会破坏我的折叠菜单?

[英]Why does ng-include break my collapse menu?

I recently bought a template to start pulling an application I am building into it. 我最近购买了一个模板,开始将要构建的应用程序拉入其中。 The navigation will have a lot of dynamic menus based on the user's roles so I would like to keep it in a separate file and pull it in versus putting it on every page and updating each one. 导航将基于用户的角色提供许多动态菜单,因此我想将其保存在一个单独的文件中,并将其放入而不是放在每个页面上并更新每个页面。 When I do use ng-include, it seems like Jquery breaks or bootstrap.min.js doesn't recognize the menus. 当我使用ng-include时,似乎Jquery中断或bootstrap.min.js无法识别菜单。

<div ng-include="'/partials/structure/navigation.html'"></div>

When I do the above it pulls in the navigation, just the mobile menu of it's not clickable. 当我执行上述操作时,它会拉入导航,只是无法单击其移动菜单。 No errors in the console either. 控制台中也没有错误。 On a full view, the menus are there and all the dropdowns work. 以全视图显示,菜单在那里,所有下拉菜单均起作用。 When I don't use ng-include both full menu and mobile menu function as you would expect. 当我不使用ng-include时,您会期望包括完整菜单和移动菜单功能。 So it seems like something with jQuery, but I am stumped where to look for this and Google didn't yield much to go off of. 因此,它似乎与jQuery相似,但是我很困惑在哪里可以找到它,而Google并没有收获太多。

                    <div class="menu-extras topbar-custom">

                     <ul class="list-inline float-right mb-0">

                        <li class="menu-item list-inline-item">
                            <!-- Mobile menu toggle-->
                            <a class="navbar-toggle nav-link">
                                <div class="lines">
                                    <span></span>
                                    <span></span>
                                    <span></span>
                                </div>
                            </a>
                            <!-- End mobile menu toggle-->
                        </li> 
                        <!-- Removed code to shorten things for you guys -->
                      </ul>
                    </div>
                <!-- end menu-extras -->

Shortening this up as well. 也要缩短它。

            <div class="navbar-custom">
            <div class="container-fluid">
                <div id="navigation">
                    <!-- Navigation Menu-->
                    <ul class="navigation-menu">

                        <li class="has-submenu">
                            <a href="index.html"><i class="ti-home"></i>Dashboard</a>
                        </li>

                        <li class="has-submenu">
                            <a href="#"><i class="ti-paint-bucket"></i>UI Kit</a>
                            <ul class="submenu">
                                <li><a href="ui-buttons.html">Buttons</a></li>
                                <li><a href="ui-cards.html">Cards</a></li>
                                <li><a href="ui-portlets.html">Portlets</a></li>
                                <li><a href="ui-checkbox-radio.html">Checkboxs-Radios</a></li>
                                <li><a href="ui-tabs.html">Tabs & Accordions</a></li>
                                <li><a href="ui-modals.html">Modals</a></li>
                                <li><a href="ui-progressbars.html">Progress Bars</a></li>
                                <li><a href="ui-notification.html">Notification</a></li>
                                <li><a href="ui-bootstrap.html">BS Elements</a></li>
                                <li><a href="ui-typography.html">Typography</a></li>
                            </ul>
                        </li>
                   </ul>
              </div>

Here is how I include everything before the tag. 这是我在标记之前包含所有内容的方式。

        <!-- jQuery  -->
    <script src="../js/jquery.min.js"></script>
    <script src="../js/popper.min.js"></script><!-- Popper for Bootstrap --><!-- Tether for Bootstrap -->
    <script src="../js/waves.js"></script>
    <script src="../js/jquery.slimscroll.js"></script>
    <script src="../js/jquery.scrollTo.min.js"></script>

    <!-- App js -->
    <script src="../js/jquery.core.js"></script>
    <script src="../js/jquery.app.js"></script>

    <!-- Angular -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>

    <!-- Controllers -->
    <script src="../js/controllers/main.js"></script>

    <!-- Bootstrap Javascript -->
    <script src="../js/bootstrap.min.js"></script>

If you include ng-include it means after only the Angular application initialization directive will render the HTML content into the DOM . 如果包含ng-include则意味着仅在Angular应用程序初始化指令之后, HTML内容才会呈现到DOM After that only the bootstrap.min.js can see the rendered menu HTML inside DOM. 之后,只有bootstrap.min.js才能在DOM中看到呈现的菜单HTML。 Therefore you need to add bootstrap.min.js after the angular code. 因此,您需要在angular代码后添加bootstrap.min.js Otherwise it won't see the HTML. 否则,它将看不到HTML。

Therefore make sure you include js in following order 因此,请确保按以下顺序包含js

jquery.js
angular.js
angular application js code
bootstrap.min.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM