Javascript 页面首次加载angularjs时通知计数未更新?
首次加载页面时,必须在页眉(导航栏)中添加通知计数。 如果页面加载,计数器将添加到通知中。但当我第一次加载时,它不会更新 我把导航条修好了。当我第一次控制台时,索引控制器没有更新。如果我再次加载,它将更新 我从存储为localstorage的webservice获取$scope.count HTML 这里是控制器获取通知计数Javascript 页面首次加载angularjs时通知计数未更新?,javascript,angularjs,Javascript,Angularjs,首次加载页面时,必须在页眉(导航栏)中添加通知计数。 如果页面加载,计数器将添加到通知中。但当我第一次加载时,它不会更新 我把导航条修好了。当我第一次控制台时,索引控制器没有更新。如果我再次加载,它将更新 我从存储为localstorage的webservice获取$scope.count HTML 这里是控制器获取通知计数 app.controller("indexController",function ($scope, $http, $window, $location, $statePa
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";
}
}
}
}
app.controller(“indexController”、函数($scope、$http、$window、$location、$stateparms、GetHostUrl、$state、$timeout、$rootScope、$localStorage){
//$rootScope.loggedInUserName=$localStorage.userName;
$scope.loggedInUserName=$localStorage.userName;
$scope.getnotification=$localStorage.getnotification;
$scope.count=“”;
if($scope.getnotification)
{
对于(var i=0;i您希望在何处显示$scope.count
?并且您的代码中有两次相同的if条件。{count}在headerif条件中,对于两种不同的内容,如果(if($scope.getnotification))则
此条件失败,count
从未获得值,检查是否通过。如果条件也失败,则不会获得响应。
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";
}
}
}
}