diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index 526ecd2e72..e0b4d11d2a 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -1,4 +1,5 @@ import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing'; +import { Title } from '@angular/platform-browser'; import { APP_BASE_HREF } from '@angular/common'; import { Http } from '@angular/http'; import { By } from '@angular/platform-browser'; @@ -264,6 +265,13 @@ describe('AppComponent', () => { expect(docViewer.innerText).toMatch(/Test Doc/i); }); + it('should update the document title', () => { + const titleService = TestBed.get(Title); + spyOn(titleService, 'setTitle'); + locationService.go('guide/pipes'); + fixture.detectChanges(); + expect(titleService.setTitle).toHaveBeenCalledWith('Angular - Pipes'); + }); }); describe('autoScrolling', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index 97eb970a54..3515c2b65d 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -1,6 +1,7 @@ import { Component, ElementRef, HostListener, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core'; import { MdSidenav } from '@angular/material'; +import { Title } from '@angular/platform-browser'; import { AutoScrollService } from 'app/shared/auto-scroll.service'; import { CurrentNode, NavigationService, NavigationViews, NavigationNode, VersionInfo } from 'app/navigation/navigation.service'; @@ -60,13 +61,17 @@ export class AppComponent implements OnInit { private documentService: DocumentService, private locationService: LocationService, private navigationService: NavigationService, - private swUpdateNotifications: SwUpdateNotificationsService + private swUpdateNotifications: SwUpdateNotificationsService, + private titleService: Title ) { } ngOnInit() { /* No need to unsubscribe because this root component never dies */ - this.documentService.currentDocument.subscribe(doc => this.currentDocument = doc); + this.documentService.currentDocument.subscribe(doc => { + this.currentDocument = doc; + this.setDocumentTitle(doc.title); + }); // scroll even if only the hash fragment changed this.locationService.currentUrl.subscribe(url => this.autoScroll()); @@ -138,4 +143,8 @@ export class AppComponent implements OnInit { sideNavToggle(value?: boolean) { this.sidenav.toggle(value); } + + setDocumentTitle(title) { + this.titleService.setTitle(`Angular - ${title}`); + } }