在angularjs刷新页面页眉 [英] Refresh header page in angularjs

查看:211
本文介绍了在angularjs刷新页面页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须登录之后刷新了header.html在angularjs。当登录被调用时,整个页面被刷新,头被初始化,但只登录内容加载后没有标题。我能做些什么来刷新头。

I have to refresh header.html after Login in angularjs. When Login is called, the whole page is refreshed and header is initialized but after login only content is loaded not header. What can i do to refresh header.

<div class="container-holder" ng-controller="mainCtrl">
    <div class="container">
        <div ng-include src='"elements/header.html"'></div>
        <div ng-view class="clearfix"></div>                     
    </div>
</div>

我要刷新了header.html。

I have to refresh header.html.

推荐答案

我这个奋斗了几天,当我开始使用AngularJS。只是新手......如果你的页眉/页脚是应用程序视图之外,它不会得到路由变化刷新。你必须有在页眉/页脚指令听了增加了一个明确的事件。基本上你听使用rootScope登录改变的事件上$('登录-chnaged事件',函数(){});

I struggled with this for days when I started using AngularJS. Just for newbies... If your header / footer is outside the app view, it will not get refreshed on route changes. You have to have an explicit event listening added in the header / footer directive. Basically you listen for the login-changed-event using a rootScope.$on('login-chnaged-event', function() {});

在此你必须设置变量的作用域像isLoggedIn或者是loggedInUser信息。您的登录服务应该火登录改变的事件只要登录状态的变化。这是由更新头指令范围变量的指令......这将最终重新呈现头。

In this you have to set the scope variables like isLoggedIn or the loggedInUser info. Your login service should fire the login-changed-event whenever the login status changes. This is listened by the directive which updates scope variables of header directive... which will finally rerender the header.

这篇关于在angularjs刷新页面页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆