Ok, so I run into this once a month or so. I'm writing this just so I can - hopefully - remember it this time. This isn't a bug or anything in Ionic - but I'm wondering if it should be documented a bit more clearly for people like me. (AKA old dense people.)
Alright - so given an Ionic app where templates are a dynamic title, this is not going to work:
<ion-view title="{{film.title]}">
<ion-content overflow-scroll="true" padding="true" class="has-header">
<div>
<p>The opening crawl would go here.</p>
</div>
</ion-content>
</ion-view>
Oddly - it will work sometimes - like if you happen to reload on that page itself - but not consistently. I'm sure there are Good(tm) reasons for this that make perfect sense, and I bet it revolves around Scope. I love Angular. Scope makes me want to push needles into my eyes though.
So how do you fix it? Switch to using <ion-nav-title>
.
<ion-view>
<ion-nav-title>{{film.title}}</ion-nav-title>
<ion-content overflow-scroll="true" padding="true" class="has-header">
<div>
<p>The opening crawl would go here.</p>
</div>
</ion-content>
</ion-view>
As I said - this is documented. Kinda. The docs for ion-view say:
"A text-only title to display on the parent ionNavBar. For an HTML title, such as an image, see ionNavTitle instead."
But in my mind, {{film.title}} resolves to "Foo" which is text only, so it should work. I looked at the docs for ionNavTitle too and nothing there really seems to make it obvious. Maybe the ionView docs should have a callout/note/etc about this situation? Like I said - I swear I hit this once a month - but admittedly my memory is crap and I tend to repeat mistakes all the time.
Thoughts?
Archived Comments
Guess I have been lucky to not have gotten bit by this. Good info to know though. Going to add this to my list of things to remember.
Simple and so useful. Thanksss
Thanks. Loose half an hour before found your post with how to fix this.
Great, solved my problem. Interestingly enough the view-title with a scope property worked fine when two views shared the same controller (like a list of films view, and a detail view for a clicked film). But for performance reasons I decided to give the details view it's own controller, and it broke. But this solved it. Thanks
Thanks for this, I wish it was a little better documented.
Thank you so much! I burned several hours on this one... I chalked it up to my newb-level Angular/Ionic skills, but no matter what I tried (isolated scope, inherited scope, delays before setting the value, etc.), I couldn't get it to work reliably. The "delayed set" approach worked, but is obviously a huge hack. Good to know* it's just another quirk in the Angular/Ionic environment. (*I wish I understood what *exactly* was going on, though! Possible idea for a follow-up post, maybe?... :) )
You are most welcome.
i'm still checking your solution. Maybe it's working for my project. Thank you so much. If there is something happened i will inform with you. Thanks!
We are also facing this issue and your above resolution don't works for me!!!
After lots of hours we find we add a extra template in same ionic HTML via script tag ng/template this causes blocker to ionic header updating.
Thanks.
I've just come across this and you saved me a headache. Thanks!
You are most welcome.
Thank you very much for this post. This was helpful
Very helpful. Thank you so much!