AngularJS - controller data outside ng-view

I want to be able to access the isAuthenticated scope outside of the ng-view. I tried to add an ng controller to the body, the problem is that I can't access isAuthenticated because it is inside the permission 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 nav on the home page and another 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 dont want to place navbar in all my views, I dont want to duplicate code.

+3
angularjs controller navbar ng-view


source to share


No one has answered this question yet

Check out similar questions:

4523
Thinking in AngularJS if I have a jQuery background?
3178
AngularJS: Service vs provider vs factory
1690
How does data binding work in AngularJS?
1195
How do I access the $ scope variable in the browser console using AngularJS?
1073
How to use $ scope. $ Watch and $ scope. $ Apply in AngularJS?
998
What is the difference between "@" and "=" in scope in AngularJS?
969
What are the nuances of the scope of prototype / prototypal inheritance in AngularJS?
912
'this' vs $ scope in AngularJS controllers
496
Fighting AngularJS controller twice
308
Sharing data between AngularJS controllers



All Articles
Loading...
X
Show
Funny
Dev
Pics