I am ng-include-ing a nav bar with a controller called NavCtrl which has a logout button that listens to a logout function and a logoutError field.
Both logout and logoutError are used only inside the template partial (nav.html). The partial doesn't use any scope variables from the parent or vice-versa.
The logout function works just fine on click, but the logoutError doesn't update to reflect a invalid logout response from the server. The scope variables work just fine on load, they just dont update the second time.
I cannot figure out why this is happening.
Code here:
nav.html
<div ng-controller="NavCtrl">
<!-- Nav Bar Stuff -->
<li><a href="#" ng-click="logout()" ng-hide="logoutRequestInProgress">Logout</a></li>
<!-- More Nav Bar Stuff -->
<!-- logoutError here doesn't update, but loads correctly when the page is first rendered -->
<div class="alert alert-danger alert-dismissable" ng-show="logoutError">
<strong>Logout Failed!</strong> {{ logoutError }}
</div>
</div>
nav.js
'use strict';
app.controller('NavCtrl', function ($scope, $window, $location, AuthService) {
if ($window.localStorage.token) {
$scope.logout = function () {
// Reset error vars
$scope.logoutError = null;
AuthService.logout().then(function() {
// success stuff
}, function (response) {
// !!! THIS UPDATE DOESNT WORK !!!
$scope.logoutError = 'Server Error';
});
};
}
});