AngularJS - 为所有页面上包含的页脚和页眉触发相同的事件

AngularJS - trigger same event for included footer and header on all pages

这个问题很可能是重复的,但经过一些搜索后,我无法找到对我的问题的一个很好的解释 - 如果是这样的话,我深表歉意。

嗯,我得到了一个模板,实际上是这样写的:

<div ng-include="'includes/header.html'"></div>

<section>... Template for homepage, page1, page2... </section>

<div ng-include="'includes/footer.html'"></div>

我的header.html是这样的:

<section class="header">
    <div class="wrapper">
        <a href="#/"><img id="logotype" src="images/logotype.png"></a>
        <ul id="menu">
            <li>
                <a href="#/">Home</a>
            </li>
            <li class="border-none">
                <a class="a" ng-click="chatClicked = !chatClicked">Click to chat</a>
            </li>
            <li id="logout" class="glyphicon glyphicon-off border-none">
                <a href="#/logout">Logout</a>
            </li>
        </ul>
    </div>
</section>

我的 footer.html 是这样的:

<section class="footer">
    <div class="wrapper">
        <ul id="menu-left">
            <li>
                <a href="#/">Home</a>
            </li>
            <li>
                <a class="a" ng-click="chatClicked = !chatClicked">Click to chat</a>
            </li>
    </div>
</section>

我想知道是否有办法在所有页面上打开 open/hide 这个新包含 (

<div ng-if="chatClicked" ng-controller='ChatController' ng-include="'includes/popup-chat-to-click.html'"></div>

) 每次触发事件 chatCliked - 如果可能的话 - 最好将最后一个 div?

放在哪里

好的,问题已解决 link,抱歉:

AngularJS - losing scope when using ng-include

这是 $scope 的问题。

我必须在我的控制器中添加这个:

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

                $scope.chat = { clicked: false };
}]); 

我的主要看法:

<div ng-include="'includes/header.html'"></div>

<div ng-if="chat.clicked" ng-controller='ChatController' ng-include="'modules/chat/popup-contact.html'"></div>

在我的 header.html:

<a class="a" ng-click="chat.clicked = !chat.clicked">Contact us</a>