这个问题有很好的机会成为副本,但经过一些搜索我无法找到解决问题的好方法 - 所以如果是这样我会道歉。
好吧,我得到了一个实际上这样编写的模板:
<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>
我想知道是否有办法在所有页面上打开/隐藏这个新的包含(
<div ng-if="chatClicked" ng-controller='ChatController' ng-include="'includes/popup-chat-to-click.html'"></div>
)每次触发 chatCliked 事件时 - 如果可能 - 最好放置最后一个div?
答案 0 :(得分:1)
使用此链接解决了问题,抱歉:
AngularJS - losing scope when using ng-include
这是范围问题。
我必须在我的控制器中添加它:
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>
<a class="a" ng-click="chat.clicked = !chat.clicked">Contact us</a>