How to Access nav-bar-buttons in every app controller


#1

My <nav-bar-buttons> are in my index.html file. As such, I can’t access their functions for a custom button.

In my index.html:

<ion-nav-bar class="bar-stable nav-title-slide-ios7">
  <ion-nav-buttons side="left">
    <button class="button button-assertive button-clear" ng-click="exit()">
        EXIT
    </button>
  </ion-nav-buttons>
  <ion-nav-buttons side="right">
    <button class="button button-positive button-clear" ng-click="clear()">
        CLEAR
    </button>
  </ion-nav-buttons>
</ion-nav-bar>

Now I would like to access the exit() and clear() functions, which only appear when I have logged into my app, and so need to be accessed only in a few controllers.

Is there a way to access these functions, perhaps without using $rootscope?


#2

Why not create a service for this? This way, it will be injected as a dependency for your app and be available globally.