KickerKeeper KickerKeeper - 4 months ago 48
AngularJS Question

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>




Answer

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".

Comments