我正在为Angular 6项目https://mypleaks.com开发SeoService。 我正在尝试随着内容URL动态更改来添加和更新Meta标签。
我能够console.log('18'+ title); console.log('19'+说明); 但是当我在addTag和updateTag标记中附加标题和描述时,只有静态值('myPleaks |')被附加,并且可以在检查此链接https://mypleaks.com/#/content/16/Manikarnika-Teaser-Launch-Kangana-Ranaut-Celebrates-with-Girls-的页面源代码上看到
有人可以告诉我这是什么问题。为什么元标记未使用变量的动态值更新??
export class SeoService {
constructor(public router: Router, public meta: Meta) { }
/**
* updateOgTitle
*/
public updateOgTitleWithURL() {
this.resolveUrl((title: string, description: string) => {
console.log('18 ' + title);
console.log('19 ' + description);
this.meta.updateTag({name: 'title', content: 'myPleaks | ' + title});
this.meta.updateTag({name: 'description', content: description});
this.meta.addTag({property: 'og:title', content: 'myPleaks | ' + title}, true);
this.meta.addTag({property: 'og:description', content: description}, true);
});
}
/**
* resolveUrl
*/
public resolveUrl(cb) {
const state: RouterState = this.router.routerState;
const snapshot: RouterStateSnapshot = state.snapshot;
const url = snapshot.url;
const title = url.substring(url.lastIndexOf('/') + 1, url.length);
cb(title, title);
} }
我也在服务器控制台上获得登录信息,这与某种原因有关吗??
headers: HttpHeaders { normalizedNames: Map {}, lazyUpdate: null, headers: Map {} },
status: 0,
statusText: 'Unknown Error',
url: null,
ok: false,
name: 'HttpErrorResponse',
message: 'Http failure response for (unknown url): 0 Unknown Error',
error:
ProgressEvent {
type: 'error',
target:
XMLHttpRequest {
onloadstart: null,
onprogress: null,
onabort: null,
onerror: null,
onload: null,
ontimeout: null,
onloadend: null,
_listeners: [Object],
onreadystatechange: null,
_anonymous: undefined,
readyState: 4,
response: null,
responseText: '',
responseType: 'text',
responseURL: '',
status: 0,
statusText: '',
timeout: 0,
upload: [Object],
_method: 'GET',
_url: [Object],
_sync: false,
_headers: [Object],
_loweredHeaders: [Object],
_mimeOverride: null,
_request: null,
_response: null,
_responseParts: null,
_responseHeaders: null,
_aborting: null,
_error: null,
_loadedBytes: 0,
_totalBytes: 0,
_lengthComputable: false },
currentTarget:
XMLHttpRequest {
onloadstart: null,
onprogress: null,
onabort: null,
onerror: null,
onload: null,
ontimeout: null,
onloadend: null,
_listeners: [Object],
onreadystatechange: null,
_anonymous: undefined,
readyState: 4,
response: null,
responseText: '',
responseType: 'text',
responseURL: '',
status: 0,
statusText: '',
timeout: 0,
upload: [Object],
_method: 'GET',
_url: [Object],
_sync: false,
_headers: [Object],
_loweredHeaders: [Object],
_mimeOverride: null,
_request: null,
_response: null,
_responseParts: null,
_responseHeaders: null,
_aborting: null,
_error: null,
_loadedBytes: 0,
_totalBytes: 0,
_lengthComputable: false },
lengthComputable: false,
loaded: 0,
total: 0 } }