I'm using the following to update the document title when views change:

<nav>
    <h1>Preamble BDD</h1>
    <ul>
        <li><a (click)="setTitle('Preamble BDD')" 
[routerLink]="['/']">Home</a></li>
        <li><a (click)="setTitle('Preamble BDD Changelog')" 
[routerLink]="['/changelog']">Changelog</a></li>
        <li><a (click)="setTitle('Preamble BDD API')" [routerLink]= 
"['/api']">API</a></li>
    </ul>
</nav>
<router-outlet></router-outlet>

It works but only when the user actually clicks on one of the links. 
However, when navigating via history (i.e. the browser's nav buttons) the 
document title remains unchanged and doesn't accurately reflect the current 
view. I am currently using the following in my views to get around this 
issue but it feels like something the Title service should be able to do if 
it was watching push and pop state events:

import {Component} from "@angular/core";
import {Title} from "@angular/platform-browser";

@Component({
    templateUrl: "app/home.component.html"
})

export class HomeComponent {
    constructor(private titleService: Title) { }
    ngOnInit() {
        this.titleService.setTitle("Preamble BDD");
        console.log("ngOnInit called");
    }
}

Notice the implementation for ngOnInit in the component class. As I stated 
above, I think the Title service should be able to do this by listening to 
push and popstaate events.

Please consider adding this feature to the Title service.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to