Set ion-nav-bar title from a directive


#1

I’m building an EmptyContent directive so that I have an empty state that can be reused throughout my app. It is shown based on a condition otherwise the main view is shown. The directive shows some basic content. I would also like for it to set the title in ion-nav-bar.

I can’t just put ion-view in my directive as the root element because then using view-title on the ion-view element does not actually set the title. I suspect this is because with my directive wrapping ion-view it is no longer a child element of ion-nav-view. If I remove ion-view directly from my directive and put it in the parent template around my directive then I would have to use ion-nav-title from within my directive to set the title but that will also not work because ion-nav-title needs to be an immediate descendant of ion-view.

Any suggestion as to how I can safely and reliably set the ion-nav-bar title from within a directive?

An example showing what I want to do… not how it can/should actually be done :smile:

<!-- my-directive in this example wraps its own ion-view. However, the title is always set to "A title" no matter what isEmptyShown evaluates to. -->
<my-directive ng-if="isEmptyShown"></my-directive>
<ion-view ng-if="!isEmptyShown" view-title="A title"></ion-view>