How to add buttons to ion-nav-bar dynamically?

You can use the $root property of your current $scope.

In your template:

<button class="button" ng-click="doSomething()" ng-if="$root.showExtraButton">
	I'm a button on the left of the navbar!
</button>

In your controller that needs the button:

.controller("MyController", function($scope) {
  $scope.$root.showExtraButton = true;

 $scope.$on("$stateChangeStart", function() {
   $scope.$root.showExtraButton = false;
 })
}

Here’s an example of doing this for a sidemenu : http://codepen.io/calendee/pen/mjtJL

2 Likes