45 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {Inject, Injectable, Δinject} from '@angular/core';
import {getDOM} from '../dom/dom_adapter';
/**
* Factory to create Title service.
*/
export function createTitle() {
return new Title(Δinject(DOCUMENT));
}
/**
* A service that can be used to get and set the title of a current HTML document.
*
* Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
* it is not possible to bind to the `text` property of the `HTMLTitleElement` elements
* (representing the `<title>` tag). Instead, this service can be used to set and get the current
* title value.
*
* @publicApi
*/
@Injectable({providedIn: 'root', useFactory: createTitle, deps: []})
2015-05-18 11:57:20 -07:00
export class Title {
constructor(@Inject(DOCUMENT) private _doc: any) {}
/**
* Get the title of the current HTML document.
*/
getTitle(): string { return getDOM().getTitle(this._doc); }
2015-05-18 11:57:20 -07:00
/**
* Set the title of the current HTML document.
* @param newTitle
*/
setTitle(newTitle: string) { getDOM().setTitle(this._doc, newTitle); }
2015-05-18 11:57:20 -07:00
}