Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically add buttons in Ionic to Nav-bar

I have a nav bar and I want to add a save button to the nav bar for only one screen. I was reading the blogs and everyone was saying how you declare your buttons in the view and don't access them in a controller. That is all well and good but I have to imagine people still want to hide and show nav buttons. Am I missing something?

<body ng-app="App">
      <!-- The nav bar that will be updated as we navigate -->
      <ion-nav-bar class="bar-positive">
        <ion-nav-back-button>    </ion-nav-back-button>
        <ion-nav-buttons side="right">
            <button id="saveButton" class="button button-clear">Save</button>
        </ion-nav-buttons>

      </ion-nav-bar>
      <ion-nav-view></ion-nav-view>
  </body>
like image 638
KickerKeeper Avatar asked Jan 08 '15 03:01

KickerKeeper


2 Answers

You can add buttons on left or right side in navigation bar from any screen containing <ion-view>.Like

<ion-view title="New Screen">
    <ion-nav-buttons side="primary">
        <button class="button" ng-click="doSomething()">
            New Button
        </button>
    </ion-nav-buttons>
</ion-view>

So this "New Button" will only come for "New Screen".

like image 163
Shripal Soni Avatar answered Sep 30 '22 19:09

Shripal Soni


In case you just want to hide right nav button on that perticular. You can do it with

<ion-nav-buttons side="right" >
</ion-nav-buttons>
like image 36
Swap Avatar answered Sep 30 '22 19:09

Swap