2016-06-23 16:47:54 +00:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-02-15 00:14:40 +00:00
|
|
|
import {Inject, Injectable} from '@angular/core';
|
|
|
|
|
|
2016-04-29 00:50:03 +00:00
|
|
|
import {getDOM} from '../dom/dom_adapter';
|
2017-02-15 00:14:40 +00:00
|
|
|
import {DOCUMENT} from '../dom/dom_tokens';
|
|
|
|
|
|
|
|
|
|
|
2015-07-15 10:07:02 +00:00
|
|
|
/**
|
|
|
|
|
* A service that can be used to get and set the title of a current HTML document.
|
|
|
|
|
*
|
2017-01-27 06:30:42 +00:00
|
|
|
* Since an Angular application can't be bootstrapped on the entire HTML document (`<html>` tag)
|
2015-07-15 10:07:02 +00:00
|
|
|
* 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.
|
2016-06-15 15:41:41 +00:00
|
|
|
*
|
|
|
|
|
* @experimental
|
2015-07-15 10:07:02 +00:00
|
|
|
*/
|
2017-02-15 00:14:40 +00:00
|
|
|
@Injectable()
|
2015-05-18 18:57:20 +00:00
|
|
|
export class Title {
|
2017-02-15 00:14:40 +00:00
|
|
|
constructor(@Inject(DOCUMENT) private _doc: any) {}
|
2015-07-15 10:07:02 +00:00
|
|
|
/**
|
|
|
|
|
* Get the title of the current HTML document.
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
2017-02-15 00:14:40 +00:00
|
|
|
getTitle(): string { return getDOM().getTitle(this._doc); }
|
2015-05-18 18:57:20 +00:00
|
|
|
|
2015-07-15 10:07:02 +00:00
|
|
|
/**
|
|
|
|
|
* Set the title of the current HTML document.
|
|
|
|
|
* @param newTitle
|
|
|
|
|
*/
|
2017-02-15 00:14:40 +00:00
|
|
|
setTitle(newTitle: string) { getDOM().setTitle(this._doc, newTitle); }
|
2015-05-18 18:57:20 +00:00
|
|
|
}
|