Skip to content

Commit ec7c637

Browse files
amcdnljelbourn
authored andcommitted
feat(docs): add page titles to doc pages angular#189 (angular#220)
1 parent 6170057 commit ec7c637

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

src/app/pages/component-category-list/component-category-list.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('ComponentCategoryList', () => {
2121
spyOn(component, 'ngOnInit').and.callThrough();
2222
fixture.detectChanges();
2323
expect(component.ngOnInit).toHaveBeenCalled();
24-
expect(component._componentPageTitle.title).toEqual('Component Library');
24+
expect(component._componentPageTitle.title).toEqual('Component Categories');
2525
});
2626

2727
it('should render a card for every category', () => {

src/app/pages/component-category-list/component-category-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ComponentCategoryList {
1717
public _componentPageTitle: ComponentPageTitle) {}
1818

1919
ngOnInit() {
20-
this._componentPageTitle.title = 'Component Library';
20+
this._componentPageTitle.title = 'Component Categories';
2121
}
2222
}
2323

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import {Component, NgModule} from '@angular/core';
1+
import {Component, NgModule, OnInit} from '@angular/core';
22
import {GuideItems} from '../../shared/guide-items/guide-items';
33
import {MdListModule} from '@angular/material';
44
import {RouterModule} from '@angular/router';
55
import {FooterModule} from '../../shared/footer/footer';
66
import {CommonModule} from '@angular/common';
7+
import {ComponentPageTitle} from '../page-title/page-title';
78

89
@Component({
910
selector: 'app-guides',
1011
templateUrl: './guide-list.html',
1112
styleUrls: ['./guide-list.scss']
1213
})
13-
export class GuideList {
14-
constructor(public guideItems: GuideItems) {}
14+
export class GuideList implements OnInit {
15+
constructor(public guideItems: GuideItems, public _componentPageTitle: ComponentPageTitle) {}
16+
17+
ngOnInit(): void {
18+
this._componentPageTitle.title = 'Guides';
19+
}
1520
}
1621

1722

1823
@NgModule({
1924
imports: [MdListModule, RouterModule, FooterModule, CommonModule],
2025
exports: [GuideList],
2126
declarations: [GuideList],
22-
providers: [GuideItems],
27+
providers: [GuideItems, ComponentPageTitle],
2328
})
2429
export class GuideListModule { }
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import {Component, NgModule} from '@angular/core';
2-
import {ActivatedRoute, Router, RouterModule} from '@angular/router';
1+
import {Component, NgModule, OnInit} from '@angular/core';
2+
import {ActivatedRoute, RouterModule, Router} from '@angular/router';
33
import {GuideItem, GuideItems} from '../../shared/guide-items/guide-items';
44
import {FooterModule} from '../../shared/footer/footer';
55
import {DocViewerModule} from '../../shared/doc-viewer/doc-viewer-module';
6-
6+
import {ComponentPageTitle} from '../page-title/page-title';
77

88
@Component({
99
selector: 'guide-viewer',
1010
templateUrl: './guide-viewer.html',
1111
styleUrls: ['./guide-viewer.scss'],
1212
})
13-
export class GuideViewer {
13+
export class GuideViewer implements OnInit {
1414
guide: GuideItem;
1515

1616
constructor(private _route: ActivatedRoute,
17+
private _componentPageTitle: ComponentPageTitle,
1718
private router: Router,
1819
public guideItems: GuideItems) {
1920
_route.params.subscribe(p => {
@@ -24,12 +25,16 @@ export class GuideViewer {
2425
}
2526
});
2627
}
28+
29+
ngOnInit(): void {
30+
this._componentPageTitle.title = this.guide.name;
31+
}
2732
}
2833

2934
@NgModule({
3035
imports: [DocViewerModule, FooterModule, RouterModule],
3136
exports: [GuideViewer],
3237
declarations: [GuideViewer],
33-
providers: [GuideItems],
38+
providers: [GuideItems, ComponentPageTitle],
3439
})
3540
export class GuideViewerModule {}

src/app/pages/homepage/homepage.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
import {Component, NgModule} from '@angular/core';
1+
import {Component, NgModule, OnInit} from '@angular/core';
22
import {SvgViewerModule} from '../../shared/svg-viewer/svg-viewer';
33
import {MdButtonModule} from '@angular/material';
44
import {FooterModule} from '../../shared/footer/footer';
55
import {RouterModule} from '@angular/router';
6+
import {ComponentPageTitle} from '../page-title/page-title';
67

78
@Component({
89
selector: 'app-homepage',
910
templateUrl: './homepage.html',
1011
styleUrls: ['./homepage.scss']
1112
})
12-
export class Homepage {}
13+
export class Homepage implements OnInit {
14+
constructor(public _componentPageTitle: ComponentPageTitle) {}
15+
16+
ngOnInit(): void {
17+
this._componentPageTitle.title = '';
18+
}
19+
}
1320

1421
@NgModule({
1522
imports: [SvgViewerModule, MdButtonModule, FooterModule, RouterModule],
1623
exports: [Homepage],
1724
declarations: [Homepage],
1825
})
19-
export class HomepageModule { }
26+
export class HomepageModule {}

src/app/pages/page-title/page-title.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {ComponentPageTitle} from './page-title';
2-
2+
import {Title} from '@angular/platform-browser';
33

44
describe('ComponentPageTitle', () => {
5-
const service: ComponentPageTitle = new ComponentPageTitle();
5+
const title: Title = new Title({});
6+
const service: ComponentPageTitle = new ComponentPageTitle(title);
67

78
it('should initialize title to empty string', () => {
89
expect(service._title).toEqual('');

src/app/pages/page-title/page-title.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Injectable} from '@angular/core';
2+
import {Title} from '@angular/platform-browser';
23

34
/**
45
* Service responsible for setting the title that appears above the components and guide pages.
@@ -8,5 +9,15 @@ export class ComponentPageTitle {
89
_title = '';
910

1011
get title(): string { return this._title; }
11-
set title(title: string) { this._title = title; }
12+
13+
set title(title: string) {
14+
this._title = title;
15+
if (title !== '') {
16+
title = `${title} | `;
17+
}
18+
this.bodyTitle.setTitle(`${title}Angular Material`);
19+
}
20+
21+
constructor(private bodyTitle: Title) { }
22+
1223
}

0 commit comments

Comments
 (0)