父子事件监听器

Parent and child event listener

我正在创建一个使用 bootstrap、jquery 和 inspinia 模板的网页。

我用的是3个文件 index.html - 我导入所有脚本的地方

<body ng-controller="MainCtrl" class="">

    <div id="wrapper">
        <div ng-include="'/app/components/navigation/navigation.html'"></div>
        <div ng-include="'/app/components/header and footer/headerFooter.html'"></div>
    </div>
</body>

<!-- JS -->
<script type="text/javascript" src="./assets/node_modules/jquery/dist/jquery.js"></script>
<script src="./assets/js/inspinia.js"></script>

<script type="text/javascript" src="./assets/node_modules/angular/angular.js"></script>
<script type="text/javascript" src="./assets/node_modules/bootstrap/dist/js/bootstrap.js"></script>

navigation.html - 我的侧边栏在哪里 headerFooter.html - 侧边栏切换按钮的位置

inspinia.js - 事件侦听器所在的位置

$('.navbar-minimalize').on("click", function (event) {
    $("body").toggleClass("mini-navbar");
    SmoothlyMenu();

});

问题是,为什么每当我按下按钮时,侧边栏不会变成迷你导航栏(class 不适用)就是这种设置。

但是如果所有 div 元素都在索引中并且没有使用 ng-include 按钮正确切换。

顺便说一句:我正在使用 bootstrap 3.xx

变化:

$('.navbar-minimalize').on('click, function() {});

至:

$('body').on('click', '.navbar-minimalize', function() {});

Angular 在运行时插入您的 HTML,因此您的 jQuery 代码在开始时不知道您的 DOM。