首次加载页面时,必须在标题(导航栏)中添加通知计数。 如果页面加载,则在通知中添加计数器。但是当我第一次加载时它不会更新。
我将导航栏设置为固定。当我第一次控制索引控制器时没有更新。如果我再次加载其更新的
从webservice获取$ scope.count存储为localstorage。
HTML
<a class="notify" ng-click="headernotifi()" data-toggle="dropdown"><span class="not-value1" ng-class="{'not-value': count > 0}" ng-cloak>{{count}}</span></a>
//App Config
var app = angular.module('communicator', [
'ui.router',
'angularMoment',
'setFiters'
]
);
//Route Config
我使用状态提供程序来路由文件。代码下方 的app.config(
function($stateProvider, $urlRouterProvider,$httpProvider)
{
// For any unmatched url, send to /route1
$urlRouterProvider.otherwise("/login");
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$stateProvider
.state('dsn',
{
url:"/dsn",
templateUrl:"design_and_selection.html",
controller:"Design_Controller"
}
)
}
)
这里是控制器获取通知计数。
app.controller("indexController",function ($scope, $http, $window, $location, $stateParams, GetHostUrl, $state, $timeout, $rootScope, $localStorage) {
//$rootScope.loggedInUserName = $localStorage.userName;
$scope.loggedInUserName=$localStorage.userName;
$scope.getnotification=$localStorage.getnotification;
$scope.count= "";
if($scope.getnotification)
{
for(var i=0;i<$scope.getnotification.notifications.length;i++)
{
$scope.count= 1;
if($scope.getnotification.notifications[i].status==0)
{
$scope.count = $scope.count + i;
console.log($scope.count);
}
}
}
console.log($scope.count);
$scope.clicker=1;
$scope.headernotifi= function()
{
$scope.clicker=0;
$scope.count="";
}
if($scope.getnotification)
{
for(var i=0;i<$scope.getnotification.notifications.length;i++)
{
if($scope.getnotification.notifications[i].message=="Conversation Reviewing")
{
$scope.getnotification.notifications[i].getreviewer="review";
}
if($scope.getnotification.notifications[i].message=="Conversation Approved")
{
$scope.getnotification.notifications[i].getreviewer="approve";
}
}
for(var i=0;i<$scope.getnotification.notifications.length;i++)
{
if($scope.getnotification.notifications[i].updateTime)
{
var c= $scope.getnotification.notifications[i].updateTime;
$scope.getnotification.notifications[i].gettime="c";
}
}
}
}
很抱歉无法完全放置代码。有人请帮忙。