如何解决AngularJS,导航栏中的数字在强制刷新时出现问题
我创建了一个简单的通知系统,在导航栏中显示未读通信的数量(通知)。
导航栏中的数字在4种情况下刷新:
问题是当您尝试强制刷新页面时(在浏览器中使用 ctrl + R
)。虽然所有组件都刷新得很好,但跟踪该数字的功能似乎不起作用。
这是 index.html,其中导航栏被去除了不需要的链接(只有布告栏一个)
<li ng-show="isLogged">
<a ui-sref="noticeBoard">
<span class="textColor">Notice Board
<span ng-if="notifiesNumber > 0" class="notificationNumber">{{notifiesNumber}}</span>
</span>
</a>
</li>
这里是 main.js,index.html 的控制器,覆盖了刷新的前 2 种情况
$scope.$on('checkNotificationNumber',function (event) {
noticeBoardService.getNotifiesNumber.get(function (result) {
if(result.status == "ok") $scope.notifiesNumber = result.notifiesNumber;
//This console log is just to check the correct call every time
console.log($filter('date')(new Date(),'HH:mm:ss') + " ---> " + $scope.notifiesNumber);
},function (err) {
console.log(err);
});
});
$scope.$on('user:loggedin',function(event,data) {
$scope.username = SessionService.getCurrentUsername();
$scope.isLogged = true;
$rootScope.$broadcast('checkNotificationNumber');
window.timerNotification = setInterval(()=> {
$rootScope.$broadcast('checkNotificationNumber');
},300000);
$location.path("/");
});
我没有插入 noticeBoard 控制器和 html,因为我认为它不会影响刷新情况。关于我应该如何修改以使其也能强制刷新浏览器的任何建议?
提前致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。