Start with the GlobalCtrl global controller GlobalCtrl that is added to the body or html tag, for example ng-controller="GlobalCtrl .
Doing this will allow us to save the scope of this GlobalCtrl in your only Angular page (as you use ui-router ), and we can avoid using $rootScope (actually simulating using $rootScope ).
Now, inside your GlobalCtrl define something like this:
// Using an object to avoid the scope inheritance problem of Angular // https://github.com/angular/angular.js/wiki/Understanding-Scopes $scope.globalData = {showSearchBar: true}; // This callback will be called everytime you change a page using ui-router state $scope.$on('$stateChangeStart', function(event, toState, toParams) { $scope.globalData.showSearchBar = true; // Just check for your page where you do not want to display the search bar // I'm using just an example like I don't want to display in contac-us page named state if (toState.name == 'contact-us' || toParams.foo == "bar") { $scope.globalData.showSearchBar = false; } });
Now, in index.html , just use ng-show :
<div ng-show="globalData.showSearchBar"> <input type="text" ng-model="query" /> </div>
source share