Reputation:
i want to know what is the best way for template head tag with angular 2? for example i have a list of videos and want when user click on the any video some title of video get sit in to the title tag. i have some idea like create a service and use in another components like this :
import {Injectable} from 'angular2/core';
import {Title} from 'angular2/platform/browser';
@Injectable()
export class SEOService {
private _default: any;
private _head: Element;
constructor(private _title: Title) {
this._head = document.querySelector('head');
}
public setDefault(model: any) {
this._default = model;
}
public update(model: any) {
var title = this._default.title + (model.title ? ' | ' + model.title : '');
var desc = model.description || this._default.description;
this._title.setTitle(title);
this.setMeta('description', desc);
this.setMeta('keywords', model.keywords || this._default.keywords);
}
Upvotes: 1
Views: 959
Reputation: 657741
For the page title there is the Title service. For other meta tags and other global stuff there is additional support planned but currently the title service is the only piece available.
Just import the Title
class and use its getTitle()
and setTitle()
method.
Upvotes: 2