に私たちは前にBroweserDomAdapterを使用しますがそれは、角度チームによって廃止されて見ていると、4.1.3角度角度ブレイク、移行4.1.3
に更新の真っ只中に私達の角度のいずれかのサービスを再加工しています私はそれを書き直した後の問題を把握するのに苦労しています。私が間違って何をやっている
:ここ
import { Injectable } from '@angular/core';
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { Title } from '@angular/platform-browser';
import { BrowserDomAdapter } from '@angular/platform-browser/src/browser/browser_adapter';
@Injectable()
export class SeoService {
/**
* Angular 2 Title Service
*/
/**
* <head> Element of the HTML document
*/
private headElement: HTMLElement;
/**
* <meta name="description"> Element of the document head
*/
private metaDescription: HTMLElement;
/**
* <meta name="robots"> Element of the document head
*/
private robots: HTMLElement;
dom:any;
/**
* Inject the Angular 2 Title Service
* @param titleService
*/
constructor (@Inject(DOCUMENT) private titleService: Title){
this.titleService = titleService;
/**
* get the <head> Element
* @type {any}
*/
this.dom = document;
this.headElement = this.dom.getSelection('head');
this.metaDescription = this.getOrCreateMetaElement('description');
this.robots = this.getOrCreateMetaElement('robots');
}
public getTitle(): string {
return this.titleService.getTitle();
}
public setTitle(newTitle: string) {
this.titleService.setTitle(newTitle + ' | Stareable');
}
public getMetaDescription(): string {
return this.metaDescription.getAttribute('content');
}
public setMetaDescription(description: string) {
this.metaDescription.setAttribute('content', description);
}
public getMetaRobots(): string {
return this.robots.getAttribute('content');
}
public setMetaRobots(robots: string) {
this.robots.setAttribute('content', robots);
}
/**
* get the HTML Element when it is in the markup, or create it.
* @param name
* @returns {HTMLElement}
*/
private getOrCreateMetaElement(name: string): HTMLElement {
let el: HTMLElement;
el = this.dom.getSelection('meta[name=' + name + ']');
if (el === null) {
el = this.dom.createElement('meta');
el.setAttribute('name', name);
this.headElement.appendChild(el);
}
return el;
}
}
は、コンソールでのエラーです:
ERRORエラー:(約束で)キャッチされない:例外TypeError:this.titleService.setTitleが機能 TypeError例外ではありません:this.titleService.setTitleは関数ではありません 、SeoService.setTitle
ありがとうございました!
取得中:this.metaDescription.setAttributeは関数ではありません – hisairnessag3
getOrCreateMetaElement();をどのようにリファクタリングしますか? – hisairnessag3