I have a Main controller for my app which is only responsible for showing and hiding the site header right now. However, it is not being shown again when I navigate back to the homepage (through a home link or back button). I have debugged and verified the scope variable is being set to true but the view is not reflecting this.
Here is the relevant code:
(index.html)
...
<body ng-app="mainApp" ng-controller="MainController">
<div class="container">
<div class="top-header" ng-show='showHeader'>
...
(MainController.js)
app.controller('MainController', function($scope, $location) {
init();
$scope.click = function() {
init();
}
function init() {
$scope.showHeader = false;
if ($location.path() === "/")
$scope.showHeader = true;
}
$scope.$on('$routeChangeSuccess', function(next, current) {
init();
});
});
I'm sure this is something trivial I'm missing as I'm new to AngularJS but any help would be much appreciated.