当我加载索引页面时,它会重定向到登录页面。登录后,将出现index.html。但是当我在角度应用程序中分配范围变量时,它不会第一次反映。如果我再次刷新页面,它会重新加载。在这场场景中很多人感到困惑。伙计们请任何人帮忙。
下面我提到登录后第一次没有加载的app.js.
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) {
$scope.count = $scope.getnotifications.unread;
if ($scope.count == 0) {
$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";
}
}
}
})
的index.html
<div ng-app="communicator">
<div id="loginDiv" ng-controller="indexController">
<a class="notify" ng-click="headernotifi()" data-toggle="dropdown">
<span class="not-value1" ng-class="{'not-value': count > 0}" ng-cloak>{{count}}</span>
</a>
<div class="container" ui-view style="min-height:600px;"> </div>
</div>
</div>
我需要在index.html首次获得至少$ scope.count。
其中,
$localstorage.getnotification = {
"notifications": [{
"id": 2786,
"message": "Conversation Approved",
"name": "CC Test vel",
"raisedBy": "reviewer",
"status": 0,
"updateTime": "2017-01-27 20:48:56.0",
"user_role": "Reviewer"
},
{
"id": 2492,
"message": "Conversation Approved",
"name": "Prepaid Card Activation for No Transactions",
"raisedBy": "Reviewer",
"status": 0,
"updateTime": "2017-01-19 18:50:04.0",
"user_role": "Reviewer"
}],
"unread": 2
}
提前致谢。