title: Can't show logout after successfully logging in without refresh in AngularJS
body: <p>After successfully logging in, the logout button is not visible in the header section but when I refresh the page it becomes visible and after that I can remove the cookies. How can I make it work without refreshing the page? It's a single page application in AngularJS. </p>
  
  <p>index.html</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="container" ng-controller="loginController"&gt;
      &lt;div class="row"&gt;
          &lt;ul class="top-bar-link top-bar-link-left"&gt;
              &lt;li&gt;&lt;i class="fa fa-phone"&gt;&lt;/i&gt; Call us: 090 456 7823&lt;/li&gt;
              &lt;li&gt;&lt;i class="fa fa-exchange"&gt;&lt;/i&gt; 30 Days Exchange Policy&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="top-bar-link top-bar-link-right dot"&gt;                    
              &lt;li&gt;&lt;a href="#checkout" &gt;Checkout&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="#compare"&gt;Compare&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="#sign_up" ng-show="!isauthentication"&gt;Sign up&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="#login" ng-show="!isauthentication"&gt;Login&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="" ng-show="isauthentication" ng-click="logout()" &gt;Logout&lt;/a&gt;&lt;/li&gt;                      
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>logincontroller.js</p>
  
  <pre class="lang-javascript prettyprint-override"><code>app.controller('loginController', [
      '$scope',
      '$location',
      'datafactory',
      '$cookieStore',
      function($scope, $location, datafactory, $cookieStore) {
          var keycookie;
          $scope.status;
          $scope.customers;
  
          $scope.isauthentication = false;
          init();
          function init() {
              if ($cookieStore.get('keycookie') != null) {
  
                  $scope.isauthentication = true;
  
                  console.log("print");
              } else {
  
                  $scope.isauthentication = false;
  
                  console.log("falseprint");
              }
  
          }
  
          $scope.login = function() {
              datafactory.postLogin($scope.email, $scope.password).then(
                      function(response) {
                          if (response.data.success == true) {
  
                              $cookieStore.put('keycookie',response.data.key);
                              $cookieStore.put('emailcookie',$scope.email);
                              var keycookie = $cookieStore.get('keycookie');
                              console.log(keycookie);
                              var emailcookie = $cookieStore.get('emailcookie');
                              console.log(emailcookie);
                              init();
                              console.log("login success");
  
                              $location.path("/home");
  
                          }
                      }, function(error) {
                          window.location.href = "#/login";
                      });
          }
          $scope.logout = function() {
  
              if ($cookieStore.get('keycookie') != null) {
                  $cookieStore.remove('keycookie');
                  init();
              }
              init();
          }
      } ]);
  </code></pre>