为什么我的AngularJS指令缓存了以前的值?

时间:2018-04-23 06:37:06

标签: angularjs navbar angular-directive

我使用AngularJS指令在我的Web应用程序中实现了“navbar”。用户登录后,将显示登录用户的用户名。但是,当我以其他用户身份登录时,在我手动刷新窗口之前,它仍会显示上一个用户的用户名。 这有什么解决方案吗?

这是navigation-directive.html

<header class="container" ng-controller="HomeController as vm" ng-init="vm.init()">
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">ABC app</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
</button> 
<div class="collapse navbar-collapse" id="navbarCollapse">
    <ul ng-if="vm.isLoggedIn()" class="navbar-nav ml-auto">
      <li class="nav-item">
        <a class="nav-link" href="#!/homeuser">Home</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#!/myappointments">My Appointments</span></a>
      </li>
      <li class="nav-item active">
        <a class="nav-link">Welcome!<strong> {{vm.loggedInUser}} </strong><i class="fa fa-user-circle-o"></i></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" ng-click="vm.logout()">Logout</span></a>
      </li>
    </ul>
  </div>
 </nav>
</header>

以下是navigation-directive.js

angular.module('bbms').directive('mhNavigation', mhNavigation);

function mhNavigation(){
  return{
    restrict: 'E',
    templateUrl: 'angular-app/navigation-directive/navigation-directive.html'
  };
}

在我的HomeController中,我正在做

vm.loggedInUser = response.data.username;

我已从家庭控制器中复制了相关部分

0 个答案:

没有答案