Home Menu shows and suddenly disappears on page load in Angularjs
Reply: 0

Menu shows and suddenly disappears on page load in Angularjs

user2353
1#
user2353 Published in June 19, 2018, 2:44 pm

I am showing menu in header based on application Name which I extract in Controller file but when I load/refresh the page, header shows for a blink of a second then disappears. Possible reason could be index.html file or menu loads first and then it calls controller init() function which set 'isMyApplication' to false. After that menu disappears.

index.html

<body ng-controller="NavigationController">
        <div class="navbar navbar-inverse navbar-fixed-top test-css" role="navigation" id="navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="#/overview">Overview</a>
                </div>
                <div ng-if="isMyApplication">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href="#/a">A</a>
                        </li>
                        <li>
                            <a href="#/b">B</a>
                        </li>
                        <li>
                            <a href="#/c">C</a>
                        </li>
                    </ul>
                </div>
            </div>
       </div>
</body>

NavigationController.js:

'use strict';

/* Controllers */
var limsApp = angular.module('limsApp.controller.Navigation', ['ngGrid', 'ui.keypress']);

/* Controller for Overview page */
limsApp.controller('NavigationController', function($scope, $location, $window, $route, GlobalService, LoggedInUser) {

$scope.isMyApplication = false;

function init() {
        $scope.username = LoggedInUser.username;
        if ($location.path().indexOf('testApp') > 0 && $scope.username !== '') {
            $scope.isMyApplication = true;
        }
    }
});

Everytime i refresh the page somehow menu logic inside index.html calls first after that it calls controller init() which determines whether to show menu or not. When it founds 'isMyApplication = false' then menu suddenly disappears. Can someone help me how to tackle this issue that if 'isMyApplication' set to false then menu shouldn't show.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34148 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO