3

I want to have access to the scope isAuthenticated outside the ng-view. I have tried to add ng-controller to the body, the problem is I can't have access to the isAuthenticated because it's inside the resolve block.

This is what i have:

.state('index', {
            url: '/',
            resolve: {
                isAuthenticated: function($auth) {
                    return $auth.validateUser().then(function(res) {
                        return true;
                    }, function(error) {
                        return false;
                    });
                }
            },
            controller: function($scope, isAuthenticated) {
                $scope.isAuthenticated = isAuthenticated;
            },
            templateUrl: 'index.html'
        })

I have two navbar states, one navbar at the home page and another one when the user is logged in.

<body>
    <div ng-if="isAuthenticated">
      <div ng-include="'user_navbar.html'"></div>
    </div>

    <div ng-if="!isAuthenticated">
      <div ng-include="'home_navbar.html'"></div>
    </div>
    <div ui-view></div>
</body>

I don't want to put the navbar in all my views, I don't want to duplicate code.

user2037696
  • 1,055
  • 3
  • 16
  • 33

0 Answers0