feat(aio): set the document title in the browser title
This commit is contained in:
parent
5293794316
commit
69b86925b3
|
@ -1,4 +1,5 @@
|
||||||
import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { Title } from '@angular/platform-browser';
|
||||||
import { APP_BASE_HREF } from '@angular/common';
|
import { APP_BASE_HREF } from '@angular/common';
|
||||||
import { Http } from '@angular/http';
|
import { Http } from '@angular/http';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
@ -264,6 +265,13 @@ describe('AppComponent', () => {
|
||||||
expect(docViewer.innerText).toMatch(/Test Doc/i);
|
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', () => {
|
describe('autoScrolling', () => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Component, ElementRef, HostListener, OnInit,
|
import { Component, ElementRef, HostListener, OnInit,
|
||||||
QueryList, ViewChild, ViewChildren } from '@angular/core';
|
QueryList, ViewChild, ViewChildren } from '@angular/core';
|
||||||
import { MdSidenav } from '@angular/material';
|
import { MdSidenav } from '@angular/material';
|
||||||
|
import { Title } from '@angular/platform-browser';
|
||||||
|
|
||||||
import { AutoScrollService } from 'app/shared/auto-scroll.service';
|
import { AutoScrollService } from 'app/shared/auto-scroll.service';
|
||||||
import { CurrentNode, NavigationService, NavigationViews, NavigationNode, VersionInfo } from 'app/navigation/navigation.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 documentService: DocumentService,
|
||||||
private locationService: LocationService,
|
private locationService: LocationService,
|
||||||
private navigationService: NavigationService,
|
private navigationService: NavigationService,
|
||||||
private swUpdateNotifications: SwUpdateNotificationsService
|
private swUpdateNotifications: SwUpdateNotificationsService,
|
||||||
|
private titleService: Title
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
/* No need to unsubscribe because this root component never dies */
|
/* 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
|
// scroll even if only the hash fragment changed
|
||||||
this.locationService.currentUrl.subscribe(url => this.autoScroll());
|
this.locationService.currentUrl.subscribe(url => this.autoScroll());
|
||||||
|
@ -138,4 +143,8 @@ export class AppComponent implements OnInit {
|
||||||
sideNavToggle(value?: boolean) {
|
sideNavToggle(value?: boolean) {
|
||||||
this.sidenav.toggle(value);
|
this.sidenav.toggle(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setDocumentTitle(title) {
|
||||||
|
this.titleService.setTitle(`Angular - ${title}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue