2

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.

Index.html

<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>

I have to refresh header.html.

2
  • You'll have to post some code. Commented Mar 15, 2013 at 12:30
  • 2
    Your after-login changes (e.g. username) must be reflected in mainCtrl. If that's the case, your header partial will update the bindings automatically. Commented Mar 15, 2013 at 13:02

2 Answers 2

1

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() {});

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.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to change your header template you could probably use an ng-switch i.e:

<div ng-switch on="login">
   <div ng-switch-when="true">Logged in!</div>
   <div ng-switch-default>Not Logged in</div>
</div>

and in your controller you would only need to toggle a boolean variable called $scope.login

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.