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