I have an ion-navbar with an ion-title set to what I want to display as the title in the navbar, but I would like to de-couple this from the HTML page title so that I can set the page title to something different.
For example, if the application name is AppName and the ion-title text is PageCategory, I would like Chrome and other web browsers to display the page title as PageCategory - AppName.
Is the only way to do this to not use ion-title? If I change this:
<ion-header>
<ion-navbar>
<ion-title start>{{ title }}</ion-title>
...
to this
<ion-header>
<ion-navbar>
<div start class="toolbar-title">{{ title }}</div>
...
The navbar looks the same, but the page title gets set to nothing (so it shows localhost:8100).
I tried using the Angular2 Title service, but it didn’t seem to get set at all that way. Suggestions?
There are plenty of reasons why in a desktop web application, one would want more information in the page title than in the Navbar title. For example, in Google Inbox, the Navbar title may be Inbox while the page title is Inbox - your@email.address.
Haven’t tried document.title yet. I tend to shy away from using document or window directly in Angular 2 apps.
document.title did nothing. I can’t seem to find a way to set the HTML title to something other than what is set in <ion-title>. Anyone have another suggestion?
I’m having some issues with this too. There really should be an option to control where or not <ion-title> sets the document title.
The reason I can’t simply ignore is it as another commenter suggest is that I’m making a web app which must function in the browser as well as a native deployment.
My current workaround is that Ionic 2 only sets the document title to the content of <ion-title> if it’s contained in an <ion-navbar>, so I simply changed the tag to <ion-toolbar>. Maybe this will be helpful to you.
+1 for this. I understand that the page title doesn’t matter in a headless WebView…
But we’re releasing our App not only for Android and iOS but also as progressive WebApp (by the way perfectly working even in Microsoft Edge) and additionally for Windows and macOS packaged in Atom Electron.
In Electron this even results in the native window title being renamed to the view’s title. OK, we could preventDefault() that in Electron but that leaves us with the WebApp problem.
By the way if I open an UserEdit view the title is set to “User edit” and I could live with a title like “App name > User edit” but the really annoying thing is, that if I open a modal “Please select country”, the title remains “Please select country” even after returning to the “User edit” view.
There is a simple solution for this problem (works for ionic-angular@2.0.0-rc.1): For all affected pages, add a reference to App in the constructor and set the page title on view enter. Your HTML ion-header remains as usual (referencing the title property).
import { App } from "ionic-angular";
export class MyPage {
title = "Navbar Title";
constructor(private _app: App) {
}
ionViewDidEnter() {
this._app.setTitle(this.title + " - App Name");
}
}
import { Title } from '@angular/platform-browser';
...
providers: [
Title
],
Inside a page:
import { Title } from '@angular/platform-browser';
public constructor(private titleService: Title ) { }
someMethod(){
this.titleService.setTitle ('An Awesome Title');
}