diff --git a/aio/src/app/layout/doc-viewer/doc-viewer.component.spec.ts b/aio/src/app/layout/doc-viewer/doc-viewer.component.spec.ts
index 4eebd55059..8ffcbda681 100644
--- a/aio/src/app/layout/doc-viewer/doc-viewer.component.spec.ts
+++ b/aio/src/app/layout/doc-viewer/doc-viewer.component.spec.ts
@@ -342,6 +342,28 @@ describe('DocViewerComponent', () => {
fixture.detectChanges();
expect(titleService.setTitle).toHaveBeenCalledWith('Angular - Features');
});
+
+ it('should not include hidden content of the
in the title', () => {
+ setCurrentDoc('linkFeatures
Some content');
+ fixture.detectChanges();
+ expect(titleService.setTitle).toHaveBeenCalledWith('Angular - Features');
+ });
+
+ it('should fall back to `textContent` if `innerText` is not available', () => {
+ const querySelector_ = docViewerEl.querySelector;
+ spyOn(docViewerEl, 'querySelector').and.callFake((selector: string) => {
+ const elem = querySelector_.call(docViewerEl, selector);
+ Object.defineProperties(elem, {
+ innerText: { value: undefined },
+ textContent: { value: 'Text Content' }
+ });
+ return elem;
+ });
+
+ setCurrentDoc('linkFeatures
Some content');
+ fixture.detectChanges();
+ expect(titleService.setTitle).toHaveBeenCalledWith('Angular - Text Content');
+ });
});
describe('TOC', () => {
diff --git a/aio/src/app/layout/doc-viewer/doc-viewer.component.ts b/aio/src/app/layout/doc-viewer/doc-viewer.component.ts
index 39678cbd0f..50687406a4 100644
--- a/aio/src/app/layout/doc-viewer/doc-viewer.component.ts
+++ b/aio/src/app/layout/doc-viewer/doc-viewer.component.ts
@@ -97,7 +97,7 @@ export class DocViewerComponent implements DoCheck, OnDestroy {
// Only create TOC for docs with an title
// If you don't want a TOC, add "no-toc" class to
if (titleEl) {
- title = titleEl.textContent.trim();
+ title = (titleEl.innerText || titleEl.textContent).trim();
if (!/(no-toc|notoc)/i.test(titleEl.className)) {
this.tocService.genToc(this.hostElement, docId);
titleEl.insertAdjacentHTML('afterend', '');