I am hiding and showing nav bar elements based on if the user is logged in or out.
In the main controller:
$scope.FBlogin = function(){
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
$cookies.put('userObj', response);
var accessToken = FB.getAuthResponse().accessToken;
console.log(accessToken);
authFact.setAccessToken(accessToken);
console.log(response);
$scope.out=true;
$scope.in = false;
$scope.feed = true;
$location.path("/myFeed");
$scope.$apply();
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
};
$scope.FBlogout = function(){
$scope.out = false;
$scope.in = true;
$scope.feed = false;
$cookies.remove("userObj");
$cookies.remove('accessToken');
$location.path("/");
$scope.$apply();
};
}]);
It works here when the login function is called from the list item. The login link disappears and the logout link shows.
Navigation directive (part of main controller)
<li ng-click="FBlogin()" ng-if="in"><a href="#login">Login</a></li>
<li ng-if="feed"><a href="#myFeed">My Feed</a></li>
<li id="logout" ng-click="FBlogout()" ng-if="out"><a>Logout</a></li>
angular.module('dsnApp')
.directive('navApp', function(){
return{
templateUrl: 'templates/nav.html',
controller:'mainController',
replace: 'true'
}
});
However when this button calls the login function the login button does not disappear and the logout does not show.
Login directive (part of main controller)
<div class="fbLogin" ng-controller="mainController">
<h1 style="display: inline-block">Login with <span id="facebook">facebook</span></h1><br>
<button ng-click="FBlogin()">Login</button>
</div>
app.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'templates/home.html',
controller : 'mainController'
})
// route for the about page
.when('/explore', {
templateUrl : 'templates/explore.html',
controller : 'exploreController'
})
// route for the service page
.when('/login', {
templateUrl : 'templates/login.html',
controller : 'mainController'
})
// route for the about page
.when('/myFeed', {
templateUrl : 'templates/myFeed.html',
controller : 'feedController',
authenticated : true
})
.otherwise('/', {
templateUrl : 'templates/home.html',
controller : 'mainController'
});
});
Does this have to do with scope at all?